How To Get The Current Date Time of Your Time Zone In Java

This example shows you how to get the current date time of your time zone.

Check this Get List of All TimeZone IDs example for getting your time zone ID.

DateTimeExample.java
package com.bytenota; 

import java.text.SimpleDateFormat; 
import java.util.Calendar; 
import java.util.TimeZone; 

public class DateTimeExample {
    public static void main(String[] args) { 
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 
        dateFormat.setTimeZone(TimeZone.getTimeZone("Europe/Zagreb")); 
        Calendar cal = Calendar.getInstance(); 
        String currentDateTime = dateFormat.format(cal.getTime()); 
        System.out.println(currentDateTime); // 2017-07-25 12:44:13 
    } 
} 

guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x