Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- auto unix_epoch_start = XXX;
- auto time = std::chrono::system_clock::now();
- auto delta = time - unix_epoc_start;
- auto timestamp = std::chrono::duration_cast<std::chrono::milliseconds>(delta).count();
- auto unix_timestamp = std::chrono::seconds(std::time(NULL));
- int unix_timestamp_x_1000 = std::chrono::milliseconds(unix_timestamp).count();
- std::chrono::steady_clock::now() - unix_timestamp;
- // 1 Jan 1970 (no time zone)
- std::tm c = { 0, 0, 0, 1, 0, 70, 0, 0, -1};
- // treat it as 1 Jan 1970 (your system's time zone) and get the
- // number of seconds since your system's epoch (leap seconds may
- // or may not be included)
- std::time_t l = std::mktime(&c);
- // get a calender time for that time_point in UTC. When interpreted
- // as UTC this represents the same calendar date and time as the
- // original, but if we change the timezone to the system TZ then it
- // represents a time offset from the original calendar time by as
- // much as UTC differs from the local timezone.
- std::tm m = *std::gmtime(&l);
- // Treat the new calendar time as offset time in the local TZ. Get
- // the number of seconds since the system epoch (again, leap seconds
- // may or may not be counted).
- std::time_t n = std::mktime(&m);
- l -= (n-l); // subtract the difference
- auto now = system_clock::now();
- day_point today = time_point_cast<days>(now);
- system_clock::time_point this_morning = today;
- day_point unix_epoch = day(1)/jan/1970;
- days days_since_epoch = today - unix_epoch;
- auto s = now - this_morning;
- auto tz_offset = hours(0);
- int unix_timestamp = (days_since_epoch + s + tz_offset) / seconds(1);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement