Converting DateTime + TimeZone to UTC

大兔子大兔子 提交于 2019-12-06 13:36:11

You can use DateTime in combination with TimeZoneInfo:

var utc = TimeZoneInfo.ConvertTimeToUtc(dateTimeAsEnteredByUser,
                                        timeZoneChosenByUser);

You need to make sure, that the Kind property of dateTimeAsEnteredByUser is set to DateTimeKind.Unspecified.

BTW:
The two times you specified are not the same. The first is 12:30 UTC and the second one is 11:30 UTC. Additionally, 17:00 PM doesn't exist, it's either 17:00 or 5:00 PM.

Converting to Utc:

DateTime utcDateTime = TimeZoneInfo.ConvertTimeToUtc(dateTime, timeZone);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!