-
-
Notifications
You must be signed in to change notification settings - Fork 0
wrapper_cpp
mozrin edited this page Dec 14, 2025
·
1 revision
Header-only C++ wrapper providing idiomatic C++ classes for the Universal Timestamp Library.
Copy wrappers/cpp/universal_timestamp.hpp to your include path.
- C++11 or later
- Universal Timestamp C library
#include "universal_timestamp.hpp"
#include <iostream>
int main() {
// Get current time
uts::Timestamp now = uts::Timestamp::now();
std::cout << now.format() << std::endl;
// Parse a timestamp
uts::Timestamp ts = uts::Timestamp::parse("2024-12-14T03:13:21Z");
// Comparison
if (now > ts) {
std::cout << "now is after ts" << std::endl;
}
return 0;
}g++ -std=c++11 myapp.cpp -I/path/to/include -I/path/to/wrappers/cpp \
-L/path/to/lib -l:libuniversal_timestamp.a -o myapp| Method | Description |
|---|---|
Timestamp(int64_t nanos) |
Construct from nanoseconds |
static now() |
Get current UTC time |
static now_monotonic() |
Get monotonic timestamp |
static parse(string) |
Parse ISO-8601 (strict) |
static parse_lenient(string) |
Parse ISO-8601 (lenient) |
format(bool nanos) |
Format to ISO-8601 string |
nanos() |
Get underlying nanoseconds |
to_string() |
Alias for format(true)
|
Comparison operators: ==, !=, <, <=, >, >=
Exception class thrown on parse/validation errors.
| Method | Description |
|---|---|
code() |
Get ut_error_t code |
what() |
Get error message |
| Function | Description |
|---|---|
gregorian_to_thai(year) |
Convert to Thai year |
thai_to_gregorian(year) |
Convert from Thai year |
gregorian_to_dangi(year) |
Convert to Dangi year |
dangi_to_gregorian(year) |
Convert from Dangi year |
gregorian_to_minguo(year) |
Convert to Minguo year |
minguo_to_gregorian(year) |
Convert from Minguo year |
to_japanese_era(ts) |
Get JapaneseEra struct |
to_iso_week(ts) |
Get IsoWeek struct |
Returns hardware clock precision level (0=ns, 1=µs, 2=ms, 3=s).
© 2025 Moztopia. Portions of this code and documentation are copyrighted.
All Rights Reserved.