DateTime to UnixTime Stamp in .net
{Edit} removed old reference link
Seconds since Jan 1, 1970 = unix time
To get this in VB.NET see below example (in example using DateTime.UtcNow, but you can plug in any DateTime you want there)
Dim uTime As Double
uTime = (DateTime.UtcNow - New DateTime(1970, 1, 1, 0, 0, 0)).TotalSeconds
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