Link to home
Start Free TrialLog in
Avatar of bctek
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
Avatar of Brian Mulder
Brian Mulder
Flag of Netherlands image

Hi bctek,

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)).AddSeconds(unixtimestamp)
--------


hope this helps a bit
bruintje
Avatar of bctek
bctek

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.
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(unixtimestamp)
Avatar of bctek

ASKER

hi bruintje.  i took a screenshot of the error:

www.songwave.com/ttemp/vberror.jpg
ASKER CERTIFIED SOLUTION
Avatar of ZeonFlash
ZeonFlash

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
sorry had to post
Dim ts as TimeSpan = (Date.UtcNow - new Date(1970,1,1,0,0,0))
Avatar of bctek

ASKER

the datediff worked perfectly.  sorry bruintje, that code kept generating the same error.  i use vs.net