使用 C# 将 GMT 日期转换为本地时间时遇到问题?
我们有一个用 C#(紧凑框架)编写的 Windows Mobile 应用程序。区域设置设置为(英语)新西兰。新西兰时区设置为 GMT+12。
我们以 GMT/UTC 格式存储日期。 我们的日期是 UTC 时间 2010-02-18 18:00:00,
新西兰的时间是上午 7:00。
当我们调用日期时间对象时,
starttime = starttime.ToLocalTime();
我们得到上午 9:00。
我们做错了什么?
We have a Windows Mobile application written in C# (compact framework). Regional setting is set to (English) New Zealand. Time zone is set to GMT+12 New Zealand.
We store our dates in GMT/UTC format.
We have a date 2010-02-18 18:00:00 in UTC
This time in New Zealand is 7:00 am.
When we call on a datetime object
starttime = starttime.ToLocalTime();
we get 9:00 am.
What are we doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否指定了该日期时间的“种类”?像这样的事情:
这可能会有所帮助,因为它可能不知道您现在拥有的日期时间是 Utc 类型(可能未指定)。
如果这没有帮助,也许您的一些显示如何设置开始时间的代码会有所帮助。
Have you specified the "kind" on that datetime? Something like this:
That might help as it might not know that the datetime you have now is in the type of Utc (it is probably unspecified).
If that doesn't help maybe some of your code showing how you are setting starttime would help.