Is there a cross-platform way to get the current date and time in C++?
There's always the __TIMESTAMP__
preprocessor macro.
#include <iostream>
using namespace std
void printBuildDateTime () {
cout << __TIMESTAMP__ << endl;
}
int main() {
printBuildDateTime();
}
example: Sun Apr 13 11:28:08 2014
(For fellow googlers)
There is also Boost::date_time :
#include <boost/date_time/posix_time/posix_time.hpp>
boost::posix_time::ptime date_time = boost::posix_time::microsec_clock::universal_time();
http://www.cplusplus.com/reference/ctime/strftime/
This built-in seems to offer a reasonable set of options.
std C libraries provide time().
This is seconds from the epoch and can be converted to date and H:M:S
using standard C functions. Boost also has a time/date library that you can check.
time_t timev;
time(&timev);
The ffead-cpp provides multiple utility classes for various tasks, one such class is the Date class which provides a lot of features right from Date operations to date arithmetic, there's also a Timer class provided for timing operations. You can have a look at the same.
#include <Windows.h>
void main()
{
//Following is a structure to store date / time
SYSTEMTIME SystemTime, LocalTime;
//To get the local time
int loctime = GetLocalTime(&LocalTime);
//To get the system time
int systime = GetSystemTime(&SystemTime)
}