DateTime to UnixTime Stamp in .net

后端 未结 4 1909
再見小時候
再見小時候 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:41

    I wrote these at some point - all similar to the above just with a little more detail on the old summer time adjustment thing for me here in the UK.

    Public Function UnixToTime(ByVal strUnixTime As String) As Date
        UnixToTime = DateAdd(DateInterval.Second, Val(strUnixTime), #1/1/1970#)
        If UnixToTime.IsDaylightSavingTime = True Then
            UnixToTime = DateAdd(DateInterval.Hour, 1, UnixToTime)
        End If
    End Function
    
    Public Function TimeToUnix(ByVal dteDate As Date) As String
        If dteDate.IsDaylightSavingTime = True Then
            dteDate = DateAdd(DateInterval.Hour, -1, dteDate)
        End If
        TimeToUnix = DateDiff(DateInterval.Second, #1/1/1970#, dteDate)
    End Function
    

提交回复
热议问题