我有一个使用MonoTouch开发的应用程序,该应用程序从Web服务中处理数据。该数据包含特定于时区的日期信息。该时区是UTC +12,适用于新西兰。
我的应用程序基于当前时间显示此数据。问题在于当应用程序在不同的时区使用时,由于设备上的当前时间不正确,因此数据显示不正确。
我如何获取UTC +12的当前日期和时间,而不考虑设备上的语言环境/时区设置?
编辑:
我已尝试了下面答案中提供的代码:
我的应用程序基于当前时间显示此数据。问题在于当应用程序在不同的时区使用时,由于设备上的当前时间不正确,因此数据显示不正确。
我如何获取UTC +12的当前日期和时间,而不考虑设备上的语言环境/时区设置?
编辑:
我已尝试了下面答案中提供的代码:
TimeZoneInfo.ConvertTime (DateTime.Now, TimeZoneInfo.FindSystemTimeZoneById("Pacific/Auckland"));
这段代码在我的电脑上能正常工作,但是当我在MonoTouch上运行时,会出现以下异常:
System.ArgumentException: Kind propery of dateTime is Local but the sourceTimeZone does not equal TimeZoneInfo.Local
at System.TimeZoneInfo.ConvertTime (DateTime dateTime, System.TimeZoneInfo sourceTimeZone, System.TimeZoneInfo destinationTimeZone) [0x00018] in /Developer/MonoTouch/Source/mono/mcs/class/System.Core/System/TimeZoneInfo.cs:179
at System.TimeZoneInfo.ConvertTime (DateTime dateTime, System.TimeZoneInfo destinationTimeZone) [0x00000] in /Developer/MonoTouch/Source/mono/mcs/class/System.Core/System/TimeZoneInfo.cs:173