This project provides a C++ utility to retrieve time information in different time zones. It includes a function to convert Unix timestamps into structured time representations (std::tm) adjusted for specific time zones.
The project can be compiled using a standard C++ compiler:
g++ main.cpp -o getTimeStructExampleAfter compilation, run the program:
./getTimeStructExampleThe program will output:
- Current UTC time.
- Current Beijing time (UTC+8).
- A custom timestamp converted to the Beijing time zone.
UTC Time:
Year: 2023
Month: 9
Day: 25
Hour: 14
Minute: 30
Second: 45
--------------------------
Beijing Time:
Year: 2023
Month: 9
Day: 25
Hour: 22
Minute: 30
Second: 45
--------------------------
Custom Timestamp Conversion:
Year: 2021
Month: 8
Day: 23
Hour: 20
Minute: 26
Second: 40
--------------------------
Converts a Unix timestamp to a std::tm structure adjusted for the specified time zone.
time_zone: The time zone offset from UTC in hours (e.g.,8for UTC+8).time_stamp: Optional Unix timestamp; defaults to the current system time if not provided.
A std::tm structure containing the broken-down time components for the specified time zone and timestamp.