Take the 2-minute tour ×

I'm having what is below:

#define DATE_AND_TIME_FORMAT "%Y-%m-%d %H:%M:%S"


char buffer[DATE_AND_TIME_SIZE];

static char *get_date_and_time (char *buffer) 
     time_t t = time (0);
    strftime (buffer, DATE_AND_TIME_SIZE, DATE_AND_TIME_FORMAT, localtime (&t));
    return buffer;

Can anyone of you tell me how to get a time format which includes the milliseconds "fff (according to the MSDN Microsoft)?

share|improve this question
What do you mean "deal with"? –  Jon Apr 23 '13 at 10:14
Possible duplicate of [1][1], [2][2] and [3][3]. Please check them. [1]: stackoverflow.com/questions/1695288/… [2]: stackoverflow.com/questions/3729169/… [3]: gamedev.stackexchange.com/questions/26759/… –  Atique Apr 23 '13 at 10:19
First, if you are not using Windows system clock why have you tagged it Windows? Second, you also referred to msdn, microsoft. strftime is a standard c++ function, it does not allow you to include millisecond in the format. Please write your own function to achieve what you want using the references I provided. –  Atique Apr 23 '13 at 10:31
Thanks for that. –  user2295733 Apr 23 '13 at 10:37
The millisecond fff format specfier you found on MSDN is for .Net, not C++. –  MSalters Apr 23 '13 at 10:59
show 2 more comments

1 Answer

Your time_t value has no milliseconds component, so you can safely append ".000" to your time string.

share|improve this answer
add comment

Your Answer


