cppcore
A small, portable C++ core library
Loading...
Searching...
No Matches
DateTime.h
Go to the documentation of this file.
1/*-----------------------------------------------------------------------------------------------
2The MIT License (MIT)
3
4Copyright (c) 2014-2026 Kim Kulling
5
6Permission is hereby granted, free of charge, to any person obtaining a copy of
7this software and associated documentation files (the "Software"), to deal in
8the Software without restriction, including without limitation the rights to
9use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
10the Software, and to permit persons to whom the Software is furnished to do so,
11subject to the following conditions:
12
13The above copyright notice and this permission notice shall be included in all
14copies or substantial portions of the Software.
15
16THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
18FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
19COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
20IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22-----------------------------------------------------------------------------------------------*/
23#pragma once
24
26#include <ctime>
27
28namespace cppcore {
29
30//-------------------------------------------------------------------------------------------------
35//-------------------------------------------------------------------------------------------------
36struct DateTime {
37 uint32_t year{0};
38 uint32_t month{0};
39 uint32_t day{0};
40 uint32_t hour{0};
41 uint32_t minute{0};
42 uint32_t second{0};
43
46 time_t timestamp = ::time(nullptr);
47 tm dt{};
48#if defined(_WIN32)
49 ::localtime_s(&dt, &timestamp);
50#else
51 ::localtime_r(&timestamp, &dt);
52#endif
53 year = dt.tm_year + 1900;
54 month = dt.tm_mon+1;
55 day = dt.tm_mday;
56 hour = dt.tm_hour;
57 minute = dt.tm_min;
58 second = dt.tm_sec;
59 }
60};
61
62} // namespace cppcore
uint32_t year
The current year.
Definition DateTime.h:37
uint32_t minute
The current minute.
Definition DateTime.h:41
uint32_t month
The current month.
Definition DateTime.h:38
uint32_t second
The current second.
Definition DateTime.h:42
DateTime()
The class constructor.
Definition DateTime.h:45
uint32_t day
The current day.
Definition DateTime.h:39
uint32_t hour
The current hour.
Definition DateTime.h:40