Friday 15 March 2013

java - Calendar.getTime() not returning UTC date if TimeZone is defined -


Code> SimpleDateFormat formatter = New Simple Format ("DD-MM-yyyy HH: mm: SS Z"); Time zone tees = time zone top. Gate time zone (stringpool.utc); Formatter.setTimeZone (TZ); Date dtStart = null; Date dtEnd = null; Try {dtStart = formatter.parse (formatter.format (startDate.getTime ())); DtEnd = formatter.parse (formatter.format (endDate.getTime ())); } Hold (exception e) {e.getstackTrace (); }

This is necessary until I work fine in formatting the calendar timestamp to return the string date with the required timezone, but when I date the date of the date of the wire date Parsing, then it raises the local time zone again? I need to store the date object in the UTC timezone.

Any help would be highly appreciated!

You can use it:

  date local time = New date (); // Time format converter = New SimpleDateFormat ("dd / MM / yyyy: HH: mm: ss") when changing time format for GMT time from local time zone. // GMT is getting time zone, you can get the field at any time eg. UTC Converter. SettimeJon (Timezone. Get Time Zone ("GMT")); System.out.println ("local time:" + local time) ;; System.out.println ("Time in GMT:" + Converter. Format (LocalTime));   

This will:
Local time: Fri Jun 21 11:55:00 UTC 2013
Time in GMT: 21 / / P>

Cheers.

No comments:

Post a Comment