使用C#将GMT日期转换为本地时间的问题?

时间:2010-02-19 22:47:31

标签: c# datetime windows-mobile compact-framework timezone

我们有一个用C#(紧凑框架)编写的Windows Mobile应用程序。区域设置为(英语)新西兰。时区设置为GMT + 12新西兰。

我们以GMT / UTC格式存储日期。 我们的日期为2010-02-18 18:00:00,UTC

这次在新西兰上午7点。

当我们调用日期时间对象

starttime = starttime.ToLocalTime();
我们早上9点到了 我们做错了什么?

1 个答案:

答案 0 :(得分:3)

您是否在该日期时间指定了“种类”?像这样:

DateTime parsedStartTime = DateTime.SpecifyKind(
    DateTime.Parse(starttime),
    DateTimeKind.Utc);

DateTime localStartTime = parsedStartTime.DateToLocalTime();

这可能会有所帮助,因为它可能不知道您现在拥有的日期时间是Utc类型(可能未指定)。

如果这没有帮助,可能有些代码显示您如何设置启动时间会有所帮助。

相关问题