I have a system which consists of a C# back end and a Java front end. The C# back end communicates with other systems and some mobile devices.
On the C# side, my task is among others to recognize the time zone of the timestamps coming from the mobile devices and create the corresponding TimeZoneInfo
object. This is working without any problems.
On the Java side, I have to display the time zone information together with the data sent by a mobile device. I'm using the TimeZone
class to store the time zone information within my domain objects.
Now the question is how can I create a Java's TimeZon
e object which corresponds with a C#'s TimeZoneInfo
object? AFAIK the time zones do not have any unique IDs. Further on, the names are also different (e.g. in C#: "Central Europe Standard Time
", in Java "Central Europe Time
"). Not even the number of the time zones in C# and in Java is equal!

- 2,516
- 2
- 23
- 37
2 Answers
You know that "time" is independent of "time zone", so I won't belabor that point :)
"TimeZone" is really more a function of your OS than a programming language.
Android "Time Zone IDs" correspond to the standard, IANA "Olson database":
The other half of the equation is mapping .Net timezones to the "standard". This link should help:
-
1PS: Interesting MSDN link you might enjoy: http://blogs.msdn.com/b/bclteam/archive/2010/10/11/the-caveats-of-time-zone-names.aspx – paulsm4 Aug 23 '12 at 08:08
-
Actually I meant timestamps instead of time. And I need the time zone information in order to be able to display the time stamp in the local time of the device and in the UTC format. So the time zone information is really important for me :D – Tomas Walek Aug 23 '12 at 08:14
As paulsm4 says, you can map Windows names to TZDB (aka Olson, aka tz, aka zoneinfo) names - although the mapping changes periodically, and you should really look at Unicode CLDR for more details. You should be aware that the format of the mapping table has changed over time, and that some Windows IDs map to multiple TZDB IDs. (Some are missing entirely.)
As an alternative, you could consider abandoning Windows time zone IDs entirely, and use TZDB throughout the stack, if you use Noda Time, a .NET date/time API I've been working on for a while now. You'll also find your Java date/time work easier if you use Joda Time, which is the library I based the "engine" of Noda Time on. It's much nicer than using Date
and Calendar
in Java.

- 1,421,763
- 867
- 9,128
- 9,194