更新时间:2023-02-03 15:40:11
尝试一下:
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);