Thread: Todays time and date

  1. #1
    Registered User
    Join Date
    May 2002
    Posts
    11

    Todays time and date

    Hi,
    Im writing a program and I would like to display todays time and date in western standard time
    eg
    Mon May 27th 19:10:52 WST 2002

    Im using time_t like this:

    #include <time.h>

    ..program.....

    time_t datetime;
    ...for loop....
    time(&datetime);
    printf ("%s", ctime(&datetime));
    ...rest of program

    Now is there another way I can display the date and time but so that its western standard time as well
    like this:
    Mon May 27th 19:10:52 WST 2002

    Any help would be much appreciated.
    Thanks

  2. #2
    Registered User
    Join Date
    Aug 2001
    Posts
    247
    Code:
    #include <time.h>
    
      struct tm today;
      time_t time_in_secs;
      
    
      time_in_secs = time(NULL);
      today =*localtime(&time_in_secs);
      printf("%2d/%02d/%02d ", today.tm_mday,
                                         today.tm_mon+1, today.tm_year-100);
    hoping to be certified (programming in c)
    here's the news - I'm officially certified.

  3. #3
    Registered User
    Join Date
    May 2002
    Posts
    11
    ok, thanks

  4. #4
    Registered User
    Join Date
    May 2002
    Posts
    11
    can I just ask
    what 2d/%02d/%02d does exactly
    Im not familar with the 2 in that particular use

  5. #5
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    can I just ask
    what 2d/%02d/%02d does exactly
    Im not familar with the 2 in that particular use
    It's a format modifer. 2 is the field width, and 02 means two chars wide, padded with 0's.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  6. #6
    . Driveway's Avatar
    Join Date
    May 2002
    Posts
    469
    http://www.cprogramming.com/fod/ctime.html
    This might help. If I remeber it's in C++ though.
    BTW, does VC++ .NET have the function timeGetTime()? If so what header?

  7. #7
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Originally posted by Driveway
    http://www.cprogramming.com/fod/ctime.html
    This might help. If I remeber it's in C++ though.
    Yes it is C++, and it is also the same function as the original poster was already using.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  8. #8
    . Driveway's Avatar
    Join Date
    May 2002
    Posts
    469
    Oh, oops, wasn't me. It was, err, my evil twin cat

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Advancing day by day until it matches a second date
    By nhubred in forum C++ Programming
    Replies: 1
    Last Post: 05-30-2009, 08:55 AM
  2. Getting todays date in C?
    By shwetha_siddu in forum C Programming
    Replies: 1
    Last Post: 04-08-2009, 12:05 AM
  3. Checking array for string
    By Ayreon in forum C Programming
    Replies: 87
    Last Post: 03-09-2009, 03:25 PM
  4. Sending an email in C program
    By Moony in forum C Programming
    Replies: 28
    Last Post: 10-19-2006, 10:42 AM