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!
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- Sorting 3 numbers without branching [closed]
- How to maintain order of key-value in DataFrame sa
- Graphics.DrawImage() - Throws out of memory except
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
andCalendar
in Java.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":
http://developer.android.com/reference/java/util/TimeZone.html#getTimeZone%28java.lang.String%29
http://en.wikipedia.org/wiki/Tz_database
The other half of the equation is mapping .Net timezones to the "standard". This link should help: