Parsing UNIX timestamps with VB.NET

M

Mitchell Vincent

Would anyone happen to have any idea how to get a UNIX timestamp (AKA
epoch, or number of seconds since Jan 1st 1970) into a VB.NET datetime
type? I have a legacy application I'm trying to port and all the dates
and times are stored in the UNIX format..

Thanks!
 
R

rawCoder

Just add seconds in the epoch date

dim dt as Date = #1/1/1970#.AddSeconds(10327314­19)
or
dim dt as Date = new System.DateTime (1970,1,1).AddSeconds(10327314­19)

P.S.where 10327314­19 is the epoch seconds
P.S.code not compiled

HTH
rawCoder
 
T

Tom Shelton

Would anyone happen to have any idea how to get a UNIX timestamp (AKA
epoch, or number of seconds since Jan 1st 1970) into a VB.NET datetime
type? I have a legacy application I'm trying to port and all the dates
and times are stored in the UNIX format..

Thanks!

So, your dates are stored as seconds since the epoch? Then you should
be able to do something like:

Private ReadOnly EPOCH As Date = New Date (1970, 1, 1)

Dim theDate As Date = EPOCH.AddSeconds (SecondsSinceEpoch)
 
M

Mitchell Vincent

Tom said:
So, your dates are stored as seconds since the epoch? Then you should
be able to do something like:

Private ReadOnly EPOCH As Date = New Date (1970, 1, 1)

Dim theDate As Date = EPOCH.AddSeconds (SecondsSinceEpoch)

Doh. Now why didn't I think about that..

Thanks guys!!!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top