bctek
asked on
Convert date to unix date
how can i convert todays date/time into a unix date stamp?
http://en.wikipedia.org/wiki/Unix_time
http://en.wikipedia.org/wiki/Unix_time
ASKER
cant get the code to work. :(
Dim ts as TimeSpan = (DateTime.UtcNow - new DateTime(1970,1,1,0,0,0))
this line generates an error.
Dim ts as TimeSpan = (DateTime.UtcNow - new DateTime(1970,1,1,0,0,0))
this line generates an error.
what was the error? i tried it here
'.NET to Unix
Dim ts As TimeSpan = (DateTime.UtcNow - New DateTime(1970, 1, 1, 0, 0, 0))
Dim unixTime As Double = ts.TotalSeconds
'Unix To .NET
Dim winTime As Date = New DateTime(1970, 1, 1, 0, 0, 0).AddSeconds(unixtimestam p)
'.NET to Unix
Dim ts As TimeSpan = (DateTime.UtcNow - New DateTime(1970, 1, 1, 0, 0, 0))
Dim unixTime As Double = ts.TotalSeconds
'Unix To .NET
Dim winTime As Date = New DateTime(1970, 1, 1, 0, 0, 0).AddSeconds(unixtimestam
ASKER
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
strange i use vb express could that make a difference?
i changed it to
Dim ts as TimeSpan = (DateTime.UtcNow - new Date(1970,1,1,0,0,0))
with the same outcome but more importantly makes it compare 2 dates
Dim ts as TimeSpan = (DateTime.UtcNow - new Date(1970,1,1,0,0,0))
with the same outcome but more importantly makes it compare 2 dates
sorry had to post
Dim ts as TimeSpan = (Date.UtcNow - new Date(1970,1,1,0,0,0))
Dim ts as TimeSpan = (Date.UtcNow - new Date(1970,1,1,0,0,0))
ASKER
the datediff worked perfectly. sorry bruintje, that code kept generating the same error. i use vs.net
you could look at this message
source: http://groups.google.com/group/microsoft.public.dotnet.languages.vb/msg/1363b11c9a6d0292?hl=en&
--------
'.NET to Unix
Dim ts as TimeSpan = (DateTime.UtcNow - new DateTime(1970,1,1,0,0,0));
Dim unixTime as Double = ts.TotalSeconds;
'Unix To .NET
(new DateTime(1970,1,1,0,0,0)).
--------
hope this helps a bit
bruintje