特定时区的DateTime.Today [英] DateTime.Today for a specific time zone

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

问题描述

我需要检查某个时区是否仍在指定日期之内。类似于 DateTime.Today == DateTime.Parse( 2016-06-30)之类的东西,但是在某些时区。最好的方法是什么?

I need to check whether a certain time zone is still within a specified date. Something like DateTime.Today == DateTime.Parse("2016-06-30") but for certain time zone. What is the best way to do it?

推荐答案

您需要获取 UTC时间,找到 TimeZoneInfo ,然后将 UTC时间转换为您的 TimeZoneInfo

You need to get UTC Time, find TimeZoneInfo, and convert UTC time to your TimeZoneInfo.

DateTime utcTime = DateTime.UtcNow;
TimeZoneInfo serverZone = TimeZoneInfo.FindSystemTimeZoneById(YourTimeZoneID);
DateTime currentDateTime = TimeZoneInfo.ConvertTimeFromUtc(utcTime, serverZone);

这篇关于特定时区的DateTime.Today的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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