time.h and time_t

This is a discussion on time.h and time_t within the C++ Programming forums, part of the General Programming Boards category; i seem to having a lot! of trouble getting the system date into this format yyyymmdd and i have been ...

  1. #1
    Unregistered
    Guest

    time.h and time_t

    i seem to having a lot! of trouble getting the system date into this format yyyymmdd and i have been trying out the time_t struct thing but i cant seem to get it to work... when i try to display things using it crashes anyone have any examples

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,505
    Code:
    #include <stdio.h>
    #include <time.h>
    
    int main ( ) {
        char    buff[100];
        time_t  now;
        now = time(NULL);
        strftime( buff, sizeof(buff), "%Y%m%d", localtime(&now) );
        printf( "Now=%s\n", buff );
        return 0; 
    }

  3. #3
    Unregistered
    Guest
    salem i bow down to you lol i cant believe my problem was this simple! i forgot to time(NULL);

Popular pages Recent additions subscribe to a feed

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