-3

I'm having what is below:

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

#define DATE_AND_TIME_SIZE 25

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)?

Christian Rau
  • 45,360
  • 10
  • 108
  • 185
user2295733
  • 1
  • 1
  • 2
  • What do you mean "deal with"? – Jon Apr 23 '13 at 10:14
  • 1
    Possible duplicate of [1][1], [2][2] and [3][3]. Please check them. [1]: http://stackoverflow.com/questions/1695288/getting-the-current-time-in-milliseconds-from-the-system-clock-in-windows [2]: http://stackoverflow.com/questions/3729169/how-can-i-get-the-windows-system-time-with-millisecond-resolution [3]: http://gamedev.stackexchange.com/questions/26759/best-way-to-get-elapsed-time-in-miliseconds-in-windows – Atiq Rahman Apr 23 '13 at 10:19
  • Any answers rather than the useless ones above? – user2295733 Apr 23 '13 at 10:29
  • 1
    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. – Atiq Rahman Apr 23 '13 at 10:31
  • 1
    The millisecond `fff` format specfier you found on MSDN is for .Net, not C++. – MSalters Apr 23 '13 at 10:59

1 Answers1

1

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

MSalters
  • 173,980
  • 10
  • 155
  • 350