c - Getting currently date on a variable -
i have variable: char date[11];, , need put inside current date, example 29/06/2012.
so i'll like:
printf ("%s\n", date); and output be: 29/06/2012
i found option print date in words, fri, june 2012, not actual date in numbers.
so how can print current date in numbers?
you can reference function strftime. i'll let figure out how use :-)
since claimed have searched it, i'll provide answer:
// first of all, need include time.h #include<time.h> int main() { // you'll raw time low level "time" function time_t raw; time(&raw); // if notice, "strftime" takes "tm" structure. // that's we'll doing: convert "time_t" "tm" struct tm *time_ptr; time_ptr = localtime(&raw); // "tm", can format buffer char date[11]; strftime(date, 11, "%d/%m/%y", time_ptr); printf("today is: %s\n", date); }
Comments
Post a Comment