Wt
4.11.1
|
A localized calendar date and clock time. More...
#include <Wt/WLocalDateTime.h>
Public Member Functions | |
WLocalDateTime (const WLocale &locale=WLocale::currentLocale()) | |
Creates a Null datetime. More... | |
WLocalDateTime (const WDate &date, const WTime &time, const WLocale &locale=WLocale::currentLocale()) | |
Creates a datetime given a date and time. More... | |
bool | isNull () const |
Returns if this datetime is Null. More... | |
bool | isValid () const |
Returns if this datetime is valid. More... | |
void | setDateTime (const WDate &date, const WTime &time) |
Sets the local date and time. More... | |
void | setDateTime (const WDate &date, const WTime &time, bool dst) |
Sets the local date and time, indicating day-light savings. More... | |
void | setDate (const WDate &date) |
Sets the date part. More... | |
WDate | date () const |
Returns the date part. More... | |
void | setTime (const WTime &time) |
Sets the time part. More... | |
WTime | time () const |
Returns the time part. More... | |
int | timeZoneOffset () const |
Returns the time zone offset. More... | |
const cpp20::date::time_zone * | timeZone () const |
Returns the time zone. More... | |
WDateTime | toUTC () const |
Converts to UTC. More... | |
WString | toString () const |
Formats this datetime to a string using the locale format. More... | |
WString | toString (const WString &format) const |
Formats this datetime to a string in a custom format. More... | |
bool | operator< (const WLocalDateTime &other) const |
Compares two values. | |
bool | operator== (const WLocalDateTime &other) const |
Compares two datetime values. | |
bool | operator!= (const WLocalDateTime &other) const |
Compares two datetime values. | |
Static Public Member Functions | |
static WLocalDateTime | fromString (const WString &s, const WLocale &locale=WLocale::currentLocale()) |
Parses a string to a time using the locale format. More... | |
static WLocalDateTime | currentDateTime (const WLocale &locale=WLocale::currentLocale()) |
Reports the current datetime. More... | |
static WLocalDateTime | currentServerDateTime () |
Reports the current local server time. | |
A localized calendar date and clock time.
This presents a localized date time, which represents a date time in a given locale.
It is recommended to only use this to display timestamps to the user, and use WDateTime (which stores UTC time) throughout your business logic. For this reason, this class does not contain any methods to calculate with time.
Wt::WLocalDateTime::WLocalDateTime | ( | const WLocale & | locale = WLocale::currentLocale() | ) |
Wt::WLocalDateTime::WLocalDateTime | ( | const WDate & | date, |
const WTime & | time, | ||
const WLocale & | locale = WLocale::currentLocale() |
||
) |
Creates a datetime given a date and time.
The datetime is valid if both date
and time
are valid and the given time could correctly be interpreted in the local time zone:
|
static |
Reports the current datetime.
This method returns the current datetime in the given locale.
If no time zone has been configured for the given locale (locale.timeZone() is empty), then the offset is based on WEnvironment::timeZoneOffset().
WDate Wt::WLocalDateTime::date | ( | ) | const |
|
static |
Parses a string to a time using the locale format.
bool Wt::WLocalDateTime::isNull | ( | ) | const |
bool Wt::WLocalDateTime::isValid | ( | ) | const |
Returns if this datetime is valid.
A date time is only valid if its date and time parts are valid.
void Wt::WLocalDateTime::setDate | ( | const WDate & | date | ) |
Sets the date part.
Changes the date part part, leaving the time unmodified. If no time was set, it is set to 00:00.
Sets the local date and time.
The datetime is valid if both date
and time
are valid and the given time could correctly be interpreted in the local time zone:
Sets the local date and time, indicating day-light savings.
The datetime is valid if both date
and time
are valid and the given time could correctly be interpreted in the local time zone with the indicated day light savings indication.
void Wt::WLocalDateTime::setTime | ( | const WTime & | time | ) |
const cpp20::date::time_zone * Wt::WLocalDateTime::timeZone | ( | ) | const |
Returns the time zone.
int Wt::WLocalDateTime::timeZoneOffset | ( | ) | const |
Returns the time zone offset.
This returns the time zone offset to UTC in minutes. A positive value thus means that the local time is ahead of UTC.
WException | if this object was initialized without timezone information |
WString Wt::WLocalDateTime::toString | ( | ) | const |
Formats this datetime to a string using the locale format.
Formats this datetime to a string in a custom format.
WDateTime Wt::WLocalDateTime::toUTC | ( | ) | const |
Converts to UTC.
This is the reverse of WDateTime::toLocalTime()