DateTime to UnixTime Stamp in .net

后端 未结 4 1904
再見小時候
再見小時候 2020-12-10 06:54

Is there any function in vb dot net to convert datetime to unix time stamp If I google I get only the vice versa but not vb.net to unix time stamp

Any help is appre

4条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-10 07:26

    In javascript, at least, unix timestamps are milliseconds, and I found a case where I needed them. This code makes use of .Net using 10,000 ticks / millisecond. Here's the code I used:

    Public Module UnixTime
        Const UnixEraStartTicks As Long = 621355968000000000
         Public Function UnixTimestamp(value As Date) As Long
            Dim UnixEraTicks = value.Ticks - UnixEraStartTicks
            Return UnixEraTicks \ 10000
        End Function
        Public Function DateFromUnix(timestamp As Long) As Date
            Return New Date(UnixEraStartTicks + timestamp * 10000)
        End Function
    End Module
    

提交回复
热议问题