Placing the Current Time in a tm structure

This is a discussion on Placing the Current Time in a tm structure within the Linux Programming forums, part of the Platform Specific Boards category; Okay here is what I am trying to do. I have included the time.h header which allows me to create ...

  1. #1
    Registered User
    Join Date
    Apr 2002
    Posts
    110

    Placing the Current Time in a tm structure

    Okay here is what I am trying to do.
    I have included the time.h header which allows me to create tm structutes.

    The beuty of using a tm structure is that it allows you to break down the time into years, months, days, hours, minutes, seconds and so on.

    Now it would make things easier if i could just place the name that I called the structure equal to time() but that doesn't seem to work.

    If anyone has a way of doing this it would be of greate help.

    Buy the way it is a linux based program (obviously).

    Later,
    WebmasterMattD
    WebmasterMattD.NET

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,505
    If you want to turn a time() into a struct tm, use gmtime() or localtime()

    Going the other way, it's mktime()

    Read about them in your manual pages

  3. #3
    Registered User
    Join Date
    Apr 2002
    Posts
    110
    Thanks dude.

    I will try it out.

    Later,
    WebmasterMattD
    WebmasterMattD.NET

  4. #4
    Registered User
    Join Date
    Apr 2002
    Posts
    110
    Okay tried that, works to some degree, though I am not getting the time from the computers clock when using *localtime() or *gmtime().

    is there some argument that I am missing when calling these?

    Later.
    WebmasterMattD
    WebmasterMattD.NET

  5. #5
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,505
    Code:
    time_t now = time(NULL);
    struct tm *tnow = localtime( &now );
    printf( "Day=%d\n", tnow->tm_mday );

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Immediate programming help! Please!
    By xMEGANx in forum C++ Programming
    Replies: 6
    Last Post: 02-20-2008, 11:52 AM
  2. Looking for a way to store listbox data
    By Welder in forum C Programming
    Replies: 20
    Last Post: 11-01-2007, 11:48 PM
  3. compiler build error
    By KristTlove in forum C++ Programming
    Replies: 2
    Last Post: 11-30-2003, 09:16 AM
  4. FAQ: How do i display current time and date ?
    By davie_scotland in forum FAQ Board
    Replies: 2
    Last Post: 01-24-2002, 10:18 AM
  5. Serial Communications in C
    By ExDigit in forum Windows Programming
    Replies: 7
    Last Post: 01-09-2002, 09:52 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21