C# version of Javascript Date.getTime()

前端 未结 8 1310
予麋鹿
予麋鹿 2021-02-01 21:11

What is the best way in c# to get the same result of javascript date.gettime() call?

The getTime() method returns the number of milliseconds since midnigh

8条回答
  •  名媛妹妹
    2021-02-01 21:23

    The Java and JavaScript Date.getTime() methods return the number of milliseconds since 1 Jan 1970 00:00:00 GMT.

    Since .NET represents dates in Ticks (1 Tick = 0.1 nanoseconds or 0.0001 milliseconds) since 1 Jan 0001 00:00:00 GMT, we must use a conversion formula where 621355968000000000 is the offset between the base dates in Ticks and 10000 the number of Ticks per Millisecond.

    Ticks = (MilliSeconds * 10000) + 621355968000000000
    MilliSeconds = (Ticks - 621355968000000000) / 10000
    

提交回复
热议问题