如何将C#中的时区信息转换为Java中的时区信息? [英] How to convert a time zone information in C# to a time zone information in Java?
问题描述
我的系统包含 C#后端和 Java 前端。 C#后端与其他系统和某些移动设备进行通信。
在 C#方面,我的任务是识别来自移动设备的时间戳的时区并创建相应的 TimeZoneInfo
对象。这没有任何问题。
在 Java 方面,我必须显示时区信息以及移动设备发送的数据。我正在使用 TimeZone
类在我的域对象中存储时区信息。
现在的问题是我如何创建一个Java的 TimeZon
e对象,该对象与 C#相对应 TimeZoneInfo
对象? AFAIK时区没有任何唯一ID。此外,名称也不同(例如 C#:中欧标准时间
,在 Java 中) 中欧时间
)。甚至C#和Java中的时区数量都不相同!
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!
推荐答案
你知道时间独立于时区,所以我不会说明这一点:)
You know that "time" is independent of "time zone", so I won't belabor that point :)
TimeZone实际上更像是操作系统的功能而不是编程语言。
"TimeZone" is really more a function of your OS than a programming language.
Android时区ID 对应于标准,IANAOlson数据库:
Android "Time Zone IDs" correspond to the standard, IANA "Olson database":
http://en.wikipedia.org/wiki/Tz_database
等式的另一半是将.Net时区映射到标准。此链接应该有所帮助:
The other half of the equation is mapping .Net timezones to the "standard". This link should help:
- .NET TimeZoneInfo from Olson time zone
这篇关于如何将C#中的时区信息转换为Java中的时区信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!