Is there a cross-platform way to get the current date and time in C++?
相关问题
- Sorting 3 numbers without branching [closed]
- How to compile C++ code in GDB?
- Why does const allow implicit conversion of refere
- thread_local variables initialization
- What uses more memory in c++? An 2 ints or 2 funct
相关文章
- Class layout in C++: Why are members sometimes ord
- How to mock methods return object with deleted cop
- Which is the best way to multiply a large and spar
- C++ default constructor does not initialize pointe
- How do you make an installer for your python progr
- Selecting only the first few characters in a strin
- Libgdx - Check if a key is being held down?
- What exactly do pointers store? (C++)
C++ shares its date/time functions with C. The tm structure is probably the easiest for a C++ programmer to work with - the following prints today's date:
This compiled for me on Linux (RHEL) and Windows (x64) targeting g++ and OpenMP:
http://www.cplusplus.com/reference/ctime/strftime/
This built-in seems to offer a reasonable set of options.
In C++ 11 you can use
std::chrono::system_clock::now()
Example (copied from en.cppreference.com):
This should print something like this:
std C libraries provide
time()
. This is seconds from the epoch and can be converted to date andH:M:S
using standard C functions. Boost also has a time/date library that you can check.