EST time

Created at 25 Mar 2021, 23:10
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
EY

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


@eynt
Replies

amusleh
26 Mar 2021, 08:49

RE:

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.


@amusleh

eynt
26 Mar 2021, 10:48

RE: RE:

Works well. Thank you!

 


@eynt