DotNetDupe 4.0.6
C++17/20 Implementation of the .NET Base Class Library (BCL)
Loading...
Searching...
No Matches
DateTimeOffset.cpp
Go to the documentation of this file.
1#include "pch.h"
4#include "System/String.h"
5#include <ctime>
6#include <cstdio>
7
8namespace DotNetDupe {
9 namespace System {
14
19
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}
Represents a point in time, typically expressed as a date and time of day, relative to Coordinated Un...
High-performance UTF-8 / UTF-16 string manipulation class mirroring .NET System.String.
Provides an abstraction for time, timestamps, and elapsed time calculation.
String ToString() const
Converts the value of the current DateTimeOffset object to its equivalent string representation.
static DateTimeOffset Now()
Gets a DateTimeOffset object that is set to the current date and time on the current computer,...
DateTimeOffset()
Initializes a new instance of DateTimeOffset to 0 ticks.
static DateTimeOffset UtcNow()
Gets a DateTimeOffset object whose date and time are set to the current Coordinated Universal Time (U...
Represents text as a sequence of UTF-8 code units with culture-invariant operations.
Definition String.h:74
String()
Initializes a new instance of the String class to an empty string.
Definition String.cpp:64
virtual DateTimeOffset GetLocalNow() const =0
Gets a DateTimeOffset value that is set to the current date and time in the local time zone.
static TimeProviderPtr GetSystem()
Gets a TimeProvider that provides the system's current time and high-resolution timer.
virtual DateTimeOffset GetUtcNow() const =0
Gets a DateTimeOffset value that is set to the current Coordinated Universal Time (UTC) date and time...