After several trial and errors, posting this for a hope to getrid of the issue with getting Todays time in JST(Japan).
Here is my first approach using Date
and SimpleDateFormat
:
SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
dateFormat.setTimeZone(TimeZone.getTimeZone("Japan"));
Date date = new Date();
System.out.println(date); // Mon Dec 08 15:29:25 IST 2014
System.out.println(dateFormat.format(date)); //12/08/2014 18:59:25
System.out.println(dateFormat.parse(dateFormat.format(date))); //Mon Dec 08 15:29:25 IST 2014
Here I am getting right one with dateFormat.format(date)
. Howerver it returns in IST when parsed to date again(dateFormat.parse(dateFormat.format(date))).
My second approach using Calendar
class:
Calendar cal = Calendar.getInstance();
cal.setTimeZone(TimeZone.getTimeZone("Japan"));
System.out.println(cal.getTime()); //Mon Dec 08 15:31:44 IST 2014
System.out.println(new Date()); //Mon Dec 08 15:31:44 IST 2014
My goal is to set Todays date in Japan time.