• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 503
  • Last Modified:

Convert date to unix date

how can i convert todays date/time into a unix date stamp?
http://en.wikipedia.org/wiki/Unix_time
0
bctek
Asked:
bctek
  • 5
  • 3
1 Solution
 
bruintjeCommented:
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
0
 
bctekAuthor Commented:
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.
0
 
bruintjeCommented:
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)
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
bctekAuthor Commented:
hi bruintje.  i took a screenshot of the error:

www.songwave.com/ttemp/vberror.jpg
0
 
ZeonFlashCommented:
Have you tried the DateDiff function?

Dim unixTime As Long = DateDiff(DateInterval.Second, New DateTime(1970, 1, 1, 0, 0, 0), DateTime.Now)
0
 
bruintjeCommented:
strange i use vb express could that make a difference?
0
 
bruintjeCommented:
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
0
 
bruintjeCommented:
sorry had to post
Dim ts as TimeSpan = (Date.UtcNow - new Date(1970,1,1,0,0,0))
0
 
bctekAuthor Commented:
the datediff worked perfectly.  sorry bruintje, that code kept generating the same error.  i use vs.net
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now