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