Time Shield Library
C++ library for working with time
Toggle main menu visibility
Loading...
Searching...
No Matches
time_zone_conversions_example.cpp
Go to the documentation of this file.
1
3
4
#include <iostream>
5
6
#include <
time_shield/time_formatting.hpp
>
7
#include <
time_shield/time_zone_conversions.hpp
>
8
9
int
main
() {
10
using namespace
time_shield
;
11
12
// Fixed-offset example: convert GMT to India Standard Time.
13
ts_t
gmt =
to_timestamp
(2024,
int
(Month::JUN), 21, 12, 0, 0);
14
ts_t
ist =
gmt_to_ist
(gmt);
15
16
// Regional alias example: Kyiv uses the EET/EEST conversion rules.
17
ts_t
kyiv =
gmt_to_kyiv
(gmt);
18
19
// Generic matrix example: convert IST local time directly to Malaysia time.
20
ts_t
ist_local =
to_timestamp
(2024,
int
(Month::JUN), 21, 17, 30, 0);
21
ts_t
myt_local =
convert_time_zone
(ist_local, TimeZone::IST, TimeZone::MYT);
22
23
std::cout <<
"GMT: "
<<
to_iso8601
(gmt) <<
'\n'
;
24
std::cout <<
"IST from GMT: "
<<
to_iso8601
(ist) <<
'\n'
;
25
std::cout <<
"Kyiv from GMT: "
<<
to_iso8601
(kyiv) <<
'\n'
;
26
std::cout <<
"MYT from IST local: "
<<
to_iso8601
(myt_local) <<
'\n'
;
27
28
return
0;
29
}
time_shield::to_iso8601
const std::string to_iso8601(T ts)
Converts a timestamp to an ISO8601 string.
Definition
time_formatting.hpp:574
time_shield::to_timestamp
TIME_SHIELD_CONSTEXPR ts_t to_timestamp(T1 year, T2 month, T2 day, T2 hour=0, T2 min=0, T2 sec=0)
Converts a date and time to a timestamp.
Definition
date_time_conversions.hpp:436
time_shield::ts_t
int64_t ts_t
Unix timestamp in seconds since 1970‑01‑01T00:00:00Z.
Definition
types.hpp:49
time_shield
Main namespace for the Time Shield library.
time_shield::gmt_to_kyiv
ts_t gmt_to_kyiv(ts_t gmt)
Convert GMT to Kyiv civil time using the EET/EEST rules.
Definition
time_zone_conversions.hpp:1062
time_shield::gmt_to_ist
ts_t gmt_to_ist(ts_t gmt)
Definition
time_zone_conversions.hpp:1014
time_shield::convert_time_zone
ts_t convert_time_zone(ts_t local, TimeZone from, TimeZone to)
Convert a timestamp between two supported local civil time zones.
Definition
time_zone_conversions.hpp:473
time_formatting.hpp
Header file for time formatting utilities.
time_zone_conversions.hpp
Helpers for converting supported regional time zones and UTC.
main
int main()
Definition
time_zone_conversions_example.cpp:9
examples
time_zone_conversions_example.cpp
Generated by
1.17.0