0

Hi im trying to store the current date and time to a file. When i print it, it is in the US format - MM/DD/YYYY

#include <time.h>

_strdate( dateStr );
cout << "Current date: " << dateStr << endl;
_strtime( timeStr );
cout << "Current time: " << timeStr;

Output:
Current date: 09/17/10
Current time: 14:20:55

I want 17/09/10, is there a way to do this? Without using a delimtter and printing the day, month, year seperatly.

Edited by Vllinator: n/a

2
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by Ancient Dragon
0

use strftime() and you can format the date any way you want. All you need is a struct tm object. And you can get that from either localtime() or mktime()

Hi, can you give me an example of how to use the strftime()?
I'm not sure what all parameters are for, as i only want to print the date and time. If i omit them it gives me an error.

cheers

0

That link already contains example code. If you don't understand it then write your own little program and play around with the format string to see what they do.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.