如何将日期时间转换为东部时间 [英] How to convert DateTime to Eastern Time

查看:80
本文介绍了如何将日期时间转换为东部时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个在金融市场开放时触发一些代码的应用程序。基本上是伪代码:做某事}

有没有一种方法可以使用C#中的DateTime对象来做到这一点?

解决方案

尝试一下:

  var timeUtc = DateTime.UtcNow; 
TimeZoneInfo EasternZone = TimeZoneInfo.FindSystemTimeZoneById(东部标准时间);
DateTime EasternTime = TimeZoneInfo.ConvertTimeFromUtc(timeUtc,EasternZone);


I'm trying to create an application that triggers some code when the financial markets are open. Basically in pseudo code:

if(9:30AM ET < Time.Now < 4:00PM ET) {//do something}

Is there a way I can do this using the DateTime object in C#?

解决方案

Try this:

var timeUtc = DateTime.UtcNow;
TimeZoneInfo easternZone = TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time");
DateTime easternTime = TimeZoneInfo.ConvertTimeFromUtc(timeUtc, easternZone);

这篇关于如何将日期时间转换为东部时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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