Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ date & time with milliseconds

Tags:

c++

date

time

Requirement

I need to retrieve the date and time including milliseconds in C++11 on Windows. If possible, beginning earlier than 1970.

I also need to be able to extract year, month, day, hour, second and millisecond from the date/time variable.

What I've tried

  • time() only returns seconds.
  • clock() doesn't return a date, only time since last system start. Good for measuring elapsed time, tho.

Note: It only has to work with Windows. Linux is not required.

like image 846
bytecode77 Avatar asked Apr 11 '13 07:04

bytecode77


1 Answers

If you are using c++11, you should use chrono which allow you to manage time easier. It gives you a few methods to "cast" your time in whatever units you want (seconds to milliseconds, ...) and can manage ctime variables too.

like image 139
Turgal Avatar answered Sep 30 '22 01:09

Turgal