Thread: Placing the Current Time in a tm structure

  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 int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    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 int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    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, 12:52 PM
  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, 10: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, 11:18 AM
  5. Serial Communications in C
    By ExDigit in forum Windows Programming
    Replies: 7
    Last Post: 01-09-2002, 10:52 AM