Monotouch UIDatePicker在1小时后出现问题。 我认为这与时区或类似的事情有关。 我试着明确地设置我的UIDatePicker的TimeZone和Locale,但这似乎没有帮助。
datePicker.Locale = NSLocale.CurrentLocale; datePicker.TimeZone = NSTimeZone.LocalTimeZone;在ValueChanged处理程序中,以下行返回比用户界面中选择的时间提前1小时的值:
var date = DateTime.SpecifyKind((s as UIDatePicker).Date, DateTimeKind.Local).ToLocalTime();在ValueChanged处理程序中,我仔细检查了Locale和TimeZone与设置的相同。 时区是欧洲/都柏林和地区en_US。 这些信息被检索到:
datePicker.Locale.LocaleIdentifier; datePicker.DatePicker.TimeZone;我错过了另一个步骤吗?
谢谢!
I'm having an issue with the Monotouch UIDatePicker being 1 hour behind. I think this is to do with Time Zones or something similar. I've tried explicitly setting the TimeZone and Locale of my UIDatePicker but this doesn't seem to be helping.
datePicker.Locale = NSLocale.CurrentLocale; datePicker.TimeZone = NSTimeZone.LocalTimeZone;In the ValueChanged handler the following line returns a value 1 hour earlier than the time selected in the user interface:
var date = DateTime.SpecifyKind((s as UIDatePicker).Date, DateTimeKind.Local).ToLocalTime();In the ValueChanged Handler I've double checked that the Locale and TimeZone is the same as what was set. The TimeZone is Europe/Dublin and Locale en_US. This information was retrieved by:
datePicker.Locale.LocaleIdentifier; datePicker.DatePicker.TimeZone;Is there another step I'm missing?
Thanks!
最满意答案
从DatePicker返回的日期是UTC格式。 有几种将UTC转换为本地时间的方法。 由于这个答案表明ToLocalTime是最好的。
DateTime.SpecifyKind(datePicker.Date, DateTimeKind.Utc).ToLocalTime();The date returned from DatePicker is in UTC format. There are several methods of converting UTC to local time. As this answer states ToLocalTime is the best one.
DateTime.SpecifyKind(datePicker.Date, DateTimeKind.Utc).ToLocalTime();更多推荐
发布评论