About
maxon::LocalDateTime is a MAXON API class used to create an object capable of representing local time and date in a convenient and effective manner to reduce the effort of handling localized time and date representation. It's indeed recommended to use the maxon::UniversalDateTime whenever possible to store normalized time and date values and convert them the localized as late as possible.
- Warning
- maxon::LocalDateTime exposes all the available members as public leaving the developer the option to customize them. It must be noted that, if the customized values are incorrect, it could lead to an unpredictable behaviour when converting back to maxon::UniversalDateTime.
Creation and initialization
A maxon::LocalDateTime can be created and initialized using:
const UInt64 aTimeStamp(1467363600);
const
maxon::
String timedateStr = "2016-07-01 09:00:00"_s;
const
Char* timedateFrmtStr = "%Y-%m-%d %H:%
M:%
S";
const
maxon::LocalDateTime ldtFromString =
maxon::LocalDateTime::FromString(timedateStr, timedateFrmtStr)
iferr_return;
Comparison
A maxon::LocalDateTime can be compared by using standard operators:
const UInt64 timestamp = 1467363600;
ldtAnother._hour -= 2;
if (ldt == ldtCloned)
{
}
if (ldtAnother != ldt)
{
DiagnosticOutput(
"ldtAnother time/date values are different than those stored in ldt.");
}
Conversion
A maxon::LocalDateTime can be converted to maxon::UniversalDateTime using:
Similarly the following methods return maxon::String representations of the maxon::LocalDateTime via:
- Note
- maxon::LocalDateTime::FormatTime() uses the same formatting specified in C++ strftime() function.
const UInt64 timestamp = 1467363600;
Utilities
A few helpful methods are provided with the maxon::LocalDateTime as utilities:
if (isLeapYear)
else
const maxon::TimeValue timezoneOffset = ldtNow.GetTimezoneOffset(&isDSTaffecting);
if (isDSTaffecting)
DiagnosticOutput(
"Local date/time is offsetted by @h respect to UTC and DST is affecting the offset", timezoneOffset.
GetHours());
else
if (isAnotherLeapYear)
else
switch (dayOfWeek)
{
dayStr = "Monday"_s;
break;
dayStr = "Tuesday"_s;
break;
dayStr = "Wednesday"_s;
break;
dayStr = "Thursday"_s;
break;
dayStr = "Friday"_s;
break;
dayStr = "Saturday"_s;
break;
dayStr = "Sunday"_s;
break;
}
Further Reading