Possible Duplicate:
Parse DateTime with timezone of form PST/CEST/UTC/etc
OK, I have following code in Java that converts my Date object into String:
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss zzz");
String str = dateFormat.format(new Date());
// outputs: 2012-12-17 15:44:57 CST
I am sending that String over the wire to WebService written in C#. So, how would I parse back that String into valid DateTime considering that following doesn’t work because zzz in C# is different:
DateTime.ParseExact(parts[2], "yyyy-MM-dd HH:mm:ss zzz", CultureInfo.InvariantCulture.DateTimeFormat);
And before anyone suggests it – I know I can go with UTC time, but I need to do it this way.
Any ideas?
CSTis not a valid .NET timezone identifier.In .NET, these are all numeric offsets –
+0700,-0500etc…You will need to output a numeric timezone offset if you want it to be parsed by .NET.
I suggest using
yyyy-MM-dd HH:mm:ss Zin Java, as can be seen here.The alternative is to convert
CSTto-0600usingstring.Replace, but this is both not scalable and can fall over with the ambiguities of named timezones (CSTcan mean different timezones depending on where you are).