DotNetDupe
4.0.6
C++17/20 Implementation of the .NET Base Class Library (BCL)
Toggle main menu visibility
Loading...
Searching...
No Matches
DateTimeOffset.cpp
Go to the documentation of this file.
1
#include "
pch.h
"
2
#include "
System/DateTimeOffset.h
"
3
#include "
System/TimeProvider.h
"
4
#include "
System/String.h
"
5
#include <ctime>
6
#include <cstdio>
7
8
namespace
DotNetDupe
{
9
namespace
System
{
10
DateTimeOffset
DateTimeOffset::Now
() {
12
return
TimeProvider::GetSystem
()->
GetLocalNow
();
13
}
14
15
DateTimeOffset
DateTimeOffset::UtcNow
() {
17
return
TimeProvider::GetSystem
()->
GetUtcNow
();
18
}
19
20
String
DateTimeOffset::ToString
()
const
{
22
return
ToString
(
"yyyy-MM-dd HH:mm:ss"
);
23
}
24
25
String
DateTimeOffset::ToString
(
const
String
& sFormat)
const
{
27
int64_t iSeconds = _ticks / 10000000LL - 62135596800LL;
28
if
(iSeconds < 0) iSeconds = 0;
29
31
std::time_t tTime =
static_cast<
std::time_t
>
(iSeconds);
32
std::tm tmTime{};
33
#if defined(_WIN32)
34
localtime_s(&tmTime, &tTime);
35
#else
36
localtime_r(&tTime, &tmTime);
37
#endif
38
40
char
szBuf[128] = { 0 };
41
std::snprintf(szBuf,
sizeof
(szBuf),
"%04d-%02d-%02d %02d:%02d:%02d"
,
42
tmTime.tm_year + 1900, tmTime.tm_mon + 1, tmTime.tm_mday,
43
tmTime.tm_hour, tmTime.tm_min, tmTime.tm_sec);
44
return
String
(szBuf);
45
}
46
}
47
}
DateTimeOffset.h
Represents a point in time, typically expressed as a date and time of day, relative to Coordinated Un...
String.h
High-performance UTF-8 / UTF-16 string manipulation class mirroring .NET System.String.
TimeProvider.h
Provides an abstraction for time, timestamps, and elapsed time calculation.
DotNetDupe::System::DateTimeOffset::ToString
String ToString() const
Converts the value of the current DateTimeOffset object to its equivalent string representation.
Definition
DateTimeOffset.cpp:20
DotNetDupe::System::DateTimeOffset::Now
static DateTimeOffset Now()
Gets a DateTimeOffset object that is set to the current date and time on the current computer,...
Definition
DateTimeOffset.cpp:10
DotNetDupe::System::DateTimeOffset::DateTimeOffset
DateTimeOffset()
Initializes a new instance of DateTimeOffset to 0 ticks.
Definition
DateTimeOffset.h:25
DotNetDupe::System::DateTimeOffset::UtcNow
static DateTimeOffset UtcNow()
Gets a DateTimeOffset object whose date and time are set to the current Coordinated Universal Time (U...
Definition
DateTimeOffset.cpp:15
DotNetDupe::System::String
Represents text as a sequence of UTF-8 code units with culture-invariant operations.
Definition
String.h:74
DotNetDupe::System::String::String
String()
Initializes a new instance of the String class to an empty string.
Definition
String.cpp:64
DotNetDupe::System::TimeProvider::GetLocalNow
virtual DateTimeOffset GetLocalNow() const =0
Gets a DateTimeOffset value that is set to the current date and time in the local time zone.
DotNetDupe::System::TimeProvider::GetSystem
static TimeProviderPtr GetSystem()
Gets a TimeProvider that provides the system's current time and high-resolution timer.
Definition
TimeProvider.cpp:84
DotNetDupe::System::TimeProvider::GetUtcNow
virtual DateTimeOffset GetUtcNow() const =0
Gets a DateTimeOffset value that is set to the current Coordinated Universal Time (UTC) date and time...
DotNetDupe::System
Definition
Action.h:11
DotNetDupe
Definition
IServiceCollection.h:7
pch.h
DotNetDupe
DateTimeOffset.cpp
Generated by
1.18.0