TimeZoneInfo.ConvertTimeFromUtc返回了错误的DateTime [英] TimeZoneInfo.ConvertTimeFromUtc returned wrong DateTime

查看:48
本文介绍了TimeZoneInfo.ConvertTimeFromUtc返回了错误的DateTime的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我叫方法:

TimeZoneInfo.ConvertTimeFromUtc(DateTime.Now.ToUniversalTime(), TimeZoneInfo.FindSystemTimeZoneById("GMT Standard Time"))  // UTC+0

它返回的DateTime比正确的DateTime大一小时.为什么?如何解决?

It is returned DateTime for one hour larger than the correct DateTime. Why? How will it fix?

返回值应等于DateTime.Now.ToUniversalTime()

Returned value should be equal DateTime.Now.ToUniversalTime()

推荐答案

UTC等于GMT.但是目前由于夏季是夏令时(格林威治标准时间+ 1),因此我们处于BST. GMT标准时间会自动调整以节省夏令时.如果您不想针对夏令时进行调整,请使用格林威治标准时间,而不要使用 GMT标准时间.

UTC is equal to GMT. But currently we're in BST due to summer, which is GMT + 1. GMT Standard Time automatically adjusts for daylight savings. Use Greenwich Standard Time, rather than GMT Standard Time if you don't want to adjust for daylight savings.

您要做的就是将 GMT标准时间更改为格林威治标准时间(请参见下文)

All you have to do is change GMT Standard Time to Greenwich Standard Time (See below)

TimeZoneInfo.ConvertTimeFromUtc(DateTime.Now.ToUniversalTime(), TimeZoneInfo.FindSystemTimeZoneById("Greenwich Standard Time"))

这篇关于TimeZoneInfo.ConvertTimeFromUtc返回了错误的DateTime的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆