Friday 15 February 2013

java - TimeZone.getTimeZone("CST") returns GMT -


I am changing time from local time with CST but getTimeZone does not work properly.

  string cstTime = "2013-06-21 14:00:00"; SimpleDateFormat simpleDateFormat = New SimpleDateFormat ("yyyy-MM-dd HH: mm: ss"); SimpleDateFormat.setTimeZone (TimeZone.getTimeZone ("CST")); Date date = null; Try {date = simpleDateFormat.parse (cstTime); } Grip (ParseException E) {System.out.println ("Pars Time Error"); E.printStackTrace (); } Timezone destTz = timezone.gate default (); // Here I should get the EDT on my phone simpleDateFormat.setTimeZone (destTz); String changed local time = simple data format. Format (date); // Changed time is "2013-06-21 10:00:00", but it should be "2013-06-21 15:00:00"   

it seems like That is to use GMT instead of CST and given below, when I have to debug:

  string ABC = "" timezone .getTimeZone ("CST"). ToString (); Println ("CST:" + ABC); Output: I / System.out (19404): CST: Java. Simplyimogen [id = GMT, offset = 0, dstswings = 3600000, use delolight = false 'a', e start, start = 0, start mode = 0, startmys = 0, start date = 0, startdream = 0, starttime = 0, napid Dot DMode = 0, endomoth = 0, and DEA = 0, endeafewyk = 0, endime = 0]   

Is it using GMT? thank you in advanced!

Edit:

Finally

  simpleDateFormat.setTimeZone (TimeZone.getTimeZone ("GMT-5")); // GMT-5 is for CDT, I found out that my server is actually using CST not CTD   

Still do not know why using the string "CST" Can not be done ...

From javadoc to getTimeZone:

  A timezone relates to an ID for an anonymous ID, or a GMT given id id area / location may be the Olson name, such as America / Los_Agelas GetAvailab LeIDs () method returns the supported name.   

Try using GetAvailableID?

No comments:

Post a Comment