本文介绍了从EST / EDT转换为GMT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将DateTime从EST / EDT转换为GMT,但不知道代码将在哪里运行(本地时区不明),也可以节省时间...

How do I convert a DateTime from EST/EDT to GMT but I don't know where the code will be ran (unknown local time zone) and also account for time savings...

推荐答案

您希望,它允许您将源时区信息作为参数传递。例如:

You want TimeZoneInfo.ConvertTimeToUtc(), which allows you to pass the source time zone info as a parameter. For example:

TimeZoneInfo est = TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time");
DateTime someDateTimeInUtc = TimeZoneInfo.ConvertTimeToUtc(someDateTime, est);

我认为这将自动处理夏令时,我想要测试它是确定的。

I think this will automatically handle daylight-saving time, but you'll want to test it to be sure.

这篇关于从EST / EDT转换为GMT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-15 11:27