Click or drag to resize

Exchange time

To work with time in S#, the DateTimeOffset structure is used. This structure stores time information in the UTC (Coordinated Universal Time)format, as well as local time offset related to the UTC. Thus, it is always possible to determine local time and offset (time zone) of the source using the DateTimeOffset.DateTime (or DateTimeOffset.LocatDateTime ) and DateTimeOffset.Offset features, correspondingly.

To determine the stock exchange time in the S#, standard C# methods can be used: DateTimeNow or DateTimeOffsetNow. For these methods to return the exact time, it is necessary to synchronize the PC local time with atomic clock by calling the TimeHelper.SyncMarketTime(Int32). method. Time offset will be recorded in the TimeHelper.NowOffset. After that, the TimeHelper.Now will store the synchronized local time, taking into consideration the TimeHelper.NowOffset. The TimeHelper class is located in the Ecng.Common namespace.

Example of getting the corrected time

  • C#
    // printing the current local time
    // doing a sync with internet clocks
    // printing the current local time again