Unix Timestamp in C++
Look up the current epoch time and convert between Unix seconds and UTC dates in C++.
Get the current timestamp
#include <chrono>
#include <iostream>
int main() {
using namespace std::chrono;
std::cout << floor<seconds>(system_clock::now()).time_since_epoch().count() << '\n';
}Timestamp to date
#include <ctime>
#include <iomanip>
#include <iostream>
int main() {
std::time_t value = 1'700'000'000;
std::cout << std::put_time(std::gmtime(&value), "%Y-%m-%dT%H:%M:%SZ") << '\n';
}Date to timestamp
#include <chrono>
#include <iostream>
int main() {
using namespace std::chrono;
auto utc = sys_days{year{2023}/November/14} + hours{22} + minutes{13} + seconds{20};
std::cout << utc.time_since_epoch().count() << '\n';
}Open 1700000000 in the converter
Current Unix time
Seconds—
Milliseconds—
- UTC
- —
- My time zone
- —
Free to use. Your input stays in this browser.
How to use it
- Copy the current-time example into your C++ environment to read Unix seconds.
- Run the second example to display 1700000000 as a UTC date.
- Run the last example to convert that date back into seconds.
These examples use the C++20 calendar API. sys_seconds represents whole seconds on the system-clock timeline, and sys_days constructs a UTC calendar day.