eynt
Joined 08.05.2020
EST time 25 Mar 2021, 23:10
How can I get current EST time by code when my time is set to a different time zone?
Thanks
amusleh 26 Mar 2021, 08:49
yuval.ein said:
How can I get current EST time by code when my time is set to a different time zone? Thanks
Try this:
using cAlgo.API; using System; namespace cAlgo { [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)] public class TimezoneSample : Indicator { protected override void Initialize() { var estTime = GetEasternStandardTime(); Print(estTime.ToString("o")); } public override void Calculate(int index) { } private DateTime GetEasternStandardTime() { var easternTimeZone = TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time"); return TimeZoneInfo.ConvertTimeFromUtc(Server.TimeInUtc, easternTimeZone); } } }
And for more info about time zones check the Microsoft Docs for TimeZoneInfo.
eynt 26 Mar 2021, 10:48
Works well. Thank you!
amusleh
26 Mar 2021, 08:49
RE:
yuval.ein said:
Try this:
And for more info about time zones check the Microsoft Docs for TimeZoneInfo.
@amusleh