converting to time_t

Discussion in 'C Programming' started by Anand CS, Jul 3, 2003.

  1. Anand CS

    Anand CS Guest

    Hi All
    I have question regarding time data structures...
    I have 64 bit unsigned microsecond resolution
    (unsigned __int64 for windows/and unsigned long long for others)
    variable. It stores the microsoconds elapsed since the Epoch...

    I want to convert this time into a string form....
    AFAIK normally the procedure from a time_t structure to string format
    is something like...convert time_ to struct tm using localtime
    method......
    as shown below..

    time_t result;
    result = time(NULL);
    printf("%s\n", asctime(localtime(&result)));

    But in my case I dont have a time_t structure as shown above but a
    unsigned 64 bit value....How do I convert this to a time_t type
    (portably) and use the same procedure shown above...

    Any suggestions
    Thanks
    Senthil
     
    Anand CS, Jul 3, 2003
    #1
    1. Advertising

  2. Anand CS wrote:

    > Hi All
    > I have question regarding time data structures...
    > I have 64 bit unsigned microsecond resolution
    > (unsigned __int64 for windows/and unsigned long long for others)
    > variable. It stores the microsoconds elapsed since the Epoch...
    >
    > I want to convert this time into a string form....
    > AFAIK normally the procedure from a time_t structure to string format
    > is something like...convert time_ to struct tm using localtime
    > method......
    > as shown below..
    >
    > time_t result;
    > result = time(NULL);
    > printf("%s\n", asctime(localtime(&result)));
    >
    > But in my case I dont have a time_t structure as shown above but a
    > unsigned 64 bit value....How do I convert this to a time_t type
    > (portably) and use the same procedure shown above...
    >
    > Any suggestions
    > Thanks
    > Senthil


    time(null) returns the number of seconds since the epoch. The easiest thing
    for you to do is something like:

    uint64_t mytime;
    time_t realtime;

    mytime = getmytimefunc();
    realtime = (time_t) (mytime / 1000000);
    printf("%s\n", asctime(localtime(&result)));

    Obviously it will loose the microsecond resolution.

    Luke
     
    Luke Driscoll, Jul 3, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?TWFyaw==?=

    DateTime to time_t bug

    =?Utf-8?B?TWFyaw==?=, May 17, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    4,711
    Steven Cheng[MSFT]
    May 18, 2004
  2. Dave Sinkula

    Casting (time_t)(-1)

    Dave Sinkula, Mar 2, 2004, in forum: C Programming
    Replies:
    4
    Views:
    660
    Dan Pop
    Mar 2, 2004
  3. j0mbolar

    time_t in seconds

    j0mbolar, Apr 18, 2004, in forum: C Programming
    Replies:
    6
    Views:
    10,328
    Dan Pop
    Apr 19, 2004
  4. Tomas Deman

    borland time_t conversion

    Tomas Deman, Jun 7, 2004, in forum: C Programming
    Replies:
    1
    Views:
    1,090
    Richard Bos
    Jun 7, 2004
  5. MrBlueSky

    timezones and time_t

    MrBlueSky, Aug 18, 2006, in forum: Python
    Replies:
    2
    Views:
    398
    MrBlueSky
    Aug 19, 2006
Loading...

Share This Page