+ Reply to Thread
Page 1 of 2
1 2 LastLast
Results 1 to 10 of 11

Thread: Odd Timestamp

  1. #1
    Programming Expert dirkfirst is on a distinguished road
    Join Date
    May 2006
    Posts
    354

    Odd Timestamp

    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

  2. #2
    Programmer brackett is on a distinguished road
    Join Date
    May 2006
    Posts
    193
    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()
    }

  3. #3
    Learning Programmer Saint is an unknown quantity at this point
    Join Date
    Aug 2006
    Posts
    63
    As for sorting you should be able to sort by that number in SQL.

    ORDER BY field ASC
    Hi >> Saint

  4. #4
    Administrator Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan's Avatar
    Join Date
    Nov 2005
    Location
    Hendersonville, NC
    Posts
    24,556
    Blog Entries
    97
    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.

  5. #5
    Programmer smith is an unknown quantity at this point
    Join Date
    Jun 2006
    Posts
    153
    Code:
    for (int i;;) {
       cout << "Smith";
    }

  6. #6
    TcM
    TcM is offline
    Code Warrior TcM is a name known to all TcM is a name known to all TcM is a name known to all TcM is a name known to all TcM is a name known to all TcM is a name known to all TcM's Avatar
    Join Date
    Aug 2006
    Posts
    11,461
    Blog Entries
    6
    So acording to that converter that timestrap is:-
    Tue, 27 Sep 2005 16:00:26 UTC
    ??
    hmm it looks like an encrypted string! cool!

  7. #7
    Programming Expert dirkfirst is on a distinguished road
    Join Date
    May 2006
    Posts
    354
    Thanks, that is exactly what that number is. Your C# code worked great brackett, thanks.
    DirkFirst

  8. #8
    Programming God NeedHelp is on a distinguished road
    Join Date
    May 2006
    Posts
    526
    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

  9. #9
    Programmer Nightracer is an unknown quantity at this point Nightracer's Avatar
    Join Date
    Jun 2006
    Posts
    131
    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????

  10. #10
    TcM
    TcM is offline
    Code Warrior TcM is a name known to all TcM is a name known to all TcM is a name known to all TcM is a name known to all TcM is a name known to all TcM is a name known to all TcM's Avatar
    Join Date
    Aug 2006
    Posts
    11,461
    Blog Entries
    6
    Well it seems that 'Who' invented it even after 1970s! llooll

+ Reply to Thread
Page 1 of 2
1 2 LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Bookmarks

Bookmarks

     
        Algorithms and Data Structures

        Java tutorials

        Algorithms Forum

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts