Does Anybody Know How I Could Get The Date (In Short Format)
Does Anybody Know How I Could Get The Date (In Short Format)
You can get the current time with time(), convert it to a tm structure with either gmtime() or localtime() and get a formatted string with strftime() from the tm structure.
You can format as ever you wish.Code:#include <stdio.h> #include <time.h> main() { char date_Ymd[8+1]; struct tm *gsapdh; time_t gsaintps; gsaintps=time(NULL); gsapdh = localtime(&gsaintps); strftime(date_Ymd, 9, "%Y%m%d", gsapdh); printf("Date_Ymd: [%s]\n",date_Ymd); }
Don't forget,
Try ctime().Code:int main() {
Hey Groorj
Thanx man, really appreciate that easy to understand, and was pretty useful for my assignment, cheers buddy :-)