Reputation: 2544
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!
Upvotes: 6
Views: 5324
Reputation: 1500675
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.
Upvotes: 5
Reputation: 121669
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:
Upvotes: 6