|
||||||
| C# Programming C# (pronounced C-sharp) is a new object oriented language from Microsoft and is derived from C and C++. It also borrows a lot of concepts from Java too including garbage collection. |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
|
|||
|
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 |
| Sponsored Links |
|
|
|
|||
|
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()
}
|
|
|||||
|
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.
__________________
CodeCall Blog | CodeCall Wiki | Shareware Site | Linux Forum | Write a Blog Don't hesitate to ask any questions that you have! Check out our ASCII Calculator! |
|
|||
|
Here is a converter - http://www.onlineconversion.com/unix_time.htm
__________________
Code:
for (int i;;) {
cout << "Smith";
}
|
| Sponsored Links |
|
|
|
|||
|
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);
__________________
I Need Help |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
Goal: 100,000 Posts
Complete: 68%