Montie Posted May 25, 2004 Posted May 25, 2004 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! Quote
Administrators PlausiblyDamp Posted May 25, 2004 Administrators Posted May 25, 2004 What does the timestamp data look like? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Montie Posted May 25, 2004 Author Posted May 25, 2004 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? Quote
Leaders Iceplug Posted May 25, 2004 Leaders Posted May 25, 2004 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 :). Quote Iceplug, USN One of my coworkers thinks that I believe that drawing bullets is the most efficient way of drawing bullets. Whatever!!! :-(
Montie Posted May 25, 2004 Author Posted May 25, 2004 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 ;) Quote
Leaders Iceplug Posted May 26, 2004 Leaders Posted May 26, 2004 That's fine if you are dealing with the seconds... if you are actually using seconds in the timestamp. Quote Iceplug, USN One of my coworkers thinks that I believe that drawing bullets is the most efficient way of drawing bullets. Whatever!!! :-(
Montie Posted May 28, 2004 Author Posted May 28, 2004 It will work... Dim d1970 As DateTime = #1/1/1970# Dim dNow As New DateTime.Now 'calculate timestamp mTS = DateDiff(DateInterval.Second, dNow, d1970) Quote
Administrators PlausiblyDamp Posted May 28, 2004 Administrators Posted May 28, 2004 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 Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.