I'm reading information from a database and came across this timestamp:
1127836826
What is that? How can I convert that to a normal date/time in C#? Is there a way to sort in SQL with this type of timestamp?
I know this may belong in the database forum but I'm more concerened with converting it in C#.
DirkFirst Tutorials | Linux Forum
I'd guess it's a UNIX timestamp - meaning, the number of seconds since 1/1/1970. In this case, it converts to 9/27/05 16:00:26 (GMT).
I don't think there's any built in conversion in .NET, so you'd just do it manually:
Code:private static DateTime EPOCH = DateTime.Parse("1/1/1970") public static DateTime UnixToDateTime(int timestamp) { return (EPOCH + TimeSpan.FromSeconds(timestamp)).ToLocalTime() }
As for sorting you should be able to sort by that number in SQL.
ORDER BY field ASC
Hi >> Saint
You can also just use the UNIXTIMESTAMP() function of MySQL and I'm sure most other DBs have a function to conver t this as well.
Here is a converter - http://www.onlineconversion.com/unix_time.htm
Code:for (int i;;) { cout << "Smith"; }
So acording to that converter that timestrap is:-
Tue, 27 Sep 2005 16:00:26 UTC
??
hmm it looks like an encrypted string! cool!
Thanks, that is exactly what that number is. Your C# code worked great brackett, thanks.
DirkFirst Tutorials | Linux Forum
Found this too, thought I would post:
Code:// This is an example of a UNIX timestamp for the date/time 11-04-2005 09:25. double timestamp = 1113211532; // First make a System.DateTime equivalent to the UNIX Epoch. System.DateTime dateTime = new System.DateTime(1970, 1, 1, 0, 0, 0, 0); // Add the number of seconds in UNIX timestamp to be converted. dateTime = dateTime.AddSeconds(timestamp); // The dateTime now contains the right date/time so to format the string, // use the standard formatting methods of the DateTime object. string printDate = dateTime.ToShortDateString() +" "+ dateTime.ToShortTimeString(); // Print the date and time System.Console.WriteLine(printDate);
First time I ran across this time stamp I had no idea what I was looking at. Who in the world would invent a time stamp that is seconds since 1970????
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks