You can print time in any format using
strftime function in C/C++.
The function declaration is as below:
size_t strftime (char* buf, int size, const char* format, const struct tm* timeptr);
- buf is the pointer to buffer.
- size is the sizeof(buf).
- timeptr is pointer to struct tm.
- format defines in which format the time to be printed. For example if you specify as "%D" it will print in MM/DD/YY date, equivalent to %m/%d/%y format. To know all the formats, refer here.
Example:
int main()
{
char buf[20];
struct tm *tptr;
time_t t(NULL);
tptr = localtime(&t);
strftime(buf, sizeof(buf), "%D", tptr);
return 0;
}
Related Posts