A new answer to a very old question.
Given the C ++ 11 or C ++ 14 compiler and this time zone library , the current time in Singapore is:
#include "tz.h" #include <iostream> int main() { using namespace std::chrono; std::cout << date::make_zoned("Asia/Singapore", system_clock::now()) << '\n'; }
which just outputs for me:
2015-08-19 05:25:05.453824 SGT
It shows the current local date, time, and abbreviation. And it is based on the <chrono> library and IANA time zone database .
std::chrono::system_clock::now() returns the timestamp in the UTC time zone. This program finds the time zone information for "Asia / Singapore" and translates the UTC timestamp into a pair representing the local time and current time zone for this location.
The above program does not depend on the current time zone of the computer.
source share