![]() |
| | #1 |
| Why bbebfe is not bbebfe? Join Date: Nov 2008 Location: Earth
Posts: 27
| Code: time_t now = time(NULL);
printf("%s\n", ctime(&now));
Any help is appreciated! |
| bbebfe is offline | |
| | #2 |
| Kernel hacker Join Date: Jul 2007 Location: Farncombe, Surrey, England
Posts: 15,686
| strftime will take a struct tm and a format string (like printf sort of), which you can get by calling localtime or gmtime. Or you could just use sprintf() with the data in struct tm, since it gives you year, month, day, etc. -- Mats
__________________ Compilers can produce warnings - make the compiler programmers happy: Use them! Please don't PM me for help - and no, I don't do help over instant messengers. |
| matsp is offline | |
| | #3 |
| Why bbebfe is not bbebfe? Join Date: Nov 2008 Location: Earth
Posts: 27
| Thank you so much! I put my code here to help others who need this two. Code: char date_buff[40];
time_t time_value = time(NULL);
struct tm* my_tm = localtime(&time_value);
strftime(date_buff, sizeof(date_buff), "%b %d,%Y\n", my_tm);
printf("%s\n", date_buff);
|
| bbebfe is offline | |
![]() |
| Tags |
| date, time |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Advancing day by day until it matches a second date | nhubred | C++ Programming | 1 | 05-30-2009 08:55 AM |
| Checking array for string | Ayreon | C Programming | 87 | 03-09-2009 03:25 PM |
| Date program starts DOS's date | jrahhali | C++ Programming | 1 | 11-24-2003 05:23 PM |
| CDate Class - handle date manipulation simply | LuckY | C++ Programming | 5 | 07-16-2003 08:35 AM |