gpt4 book ai didi

c# - 如何将 DateTime 转换为东部时间

转载 作者:IT王子 更新时间:2023-10-29 03:49:48 25 4
gpt4 key购买 nike

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

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

有没有一种方法可以使用 C# 中的 DateTime 对象执行此操作?

最佳答案

试试这个:

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

关于c# - 如何将 DateTime 转换为东部时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5997570/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com