Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Unix date format in Visual Basic.net

0 views
Skip to first unread message

Marko Maehner

unread,
Mar 12, 2004, 9:20:56 AM3/12/04
to
Hello!

I have developped a PocketPC application with CF and VB.net. Now there
are some new features to implement and in one case I have to send a
request to a WebService with several arguments and one of them is the
current date in an unix format (seconds since 01.01.1970).

Is there a possibility or an existing function to convert the current
date (now()) to this date/time format? Has someone an existing code
snipplet for this?


Thanks in advance,
Marko

Jay B. Harlow [MVP - Outlook]

unread,
Mar 14, 2004, 12:10:01 PM3/14/04
to
Marko,
The easiest way may be to use the TotalSeconds property of a Timespan.

Something like:
Dim d As DateTime = DateTime.Now
Dim ts As TimeSpan = d.Subtract(#1/1/1970#)
Dim secs As Integer = CInt(ts.TotalSeconds)

To convert a "unix format" back to DateTime you can simply add the seconds
to 1/1/70

d = #1/1/1970#.AddSeconds(secs)

Note #1/1/1970# is a date literal, which is always month, day, year
independent of the current local...

I was thinking .NET had a 'function' to do this, however I am not seeing it
right now...

Hope this helps
Jay

"Marko Maehner" <marko....@gmx.de> wrote in message
news:7a8ae685.04031...@posting.google.com...

spamfurnace

unread,
Mar 15, 2004, 4:08:52 AM3/15/04
to
.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)

hth
Richard

0 new messages