Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

How can I convert timestamp data that I got from an XML into a "normal" datetime format, that I would prefer (AND vice versa)? Of course, using Visual Basic .NET...

 

Thanks!

Posted

Timestamp is number of second since January 1st, 1970. For example - 134343235223444.

 

I mentioned that I got it from XML, but it really doesn't matter where I get it from, it could be from a text file. Can I use anything else then XMLConvert? How do I convert VB DateTime type to timestamp?

  • Leaders
Posted

Try this:

       Dim Dnought As DateTime = #1/1/1970#
       'January 1st, 1970 into this datetime.
'The ## means that it's a datetime constant.
       Dim Dfinal As DateTime = Dnought.AddSeconds(1343432352)
'Add the number of seconds to dnought to get the final date.
       MessageBox.Show(Dfinal.ToString())

 

The number that I have there gets you something in 2012. The number you have nets you something a couple hundred millenia in the future :).

Iceplug, USN

One of my coworkers thinks that I believe that drawing bullets is the most efficient way of drawing bullets. Whatever!!! :-(

Posted

Ali G would say "Aaaaiight"! ;) I say, it looks like a nice suggestion. Thanks! :)

What do you think about converting timestamp to datetime? Should I hustle with the seconds, or is there a smoother way out?

 

p.s. Yes, I know, I really didn't check the number, I just put it on the road ;)

  • Leaders
Posted
That's fine if you are dealing with the seconds... if you are actually using seconds in the timestamp.

Iceplug, USN

One of my coworkers thinks that I believe that drawing bullets is the most efficient way of drawing bullets. Whatever!!! :-(

Posted

It will work...

 

Dim d1970 As DateTime = #1/1/1970#

Dim dNow As New DateTime.Now

'calculate timestamp

mTS = DateDiff(DateInterval.Second, dNow, d1970)

  • Administrators
Posted

You are probably better of using the native .Net functions rather than the legacy VB6 DateDiff

 

it should be something like

Dim d1970 As DateTime = #1/1/1970#
Dim dNow As New DateTime.Now
Dim diff as TimeSpan
diff = dNow.Subtract(d1970)
mTS = ts.TotalSeconds

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...