Wt  3.3.8
Public Member Functions | Static Public Member Functions | List of all members
Wt::WLocalDateTime Class Reference

A localized calendar date and clock time. More...

#include <Wt/WLocalDateTime>

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...
 
std::string 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.
 

Detailed Description

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.

See also
WDateTime::toLocalTime()

Constructor & Destructor Documentation

Wt::WLocalDateTime::WLocalDateTime ( const WLocale locale = WLocale::currentLocale())

Creates a Null datetime.

A time for which isNull() returns true. A Null datetime is also invalid.

See also
isValid(), isNull()
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:

  • the time must exist (on the day that the time changes from 2AM to 3AM the time 2.30AM does not exist)
  • the time must be unambiguous. On the day that time changes from 3AM to 2AM, the time 2.30AM is not unambiguous. In that case the ambiguity must be resolved by using setDateTime() indicating whether the time is day light savings time or not.

Member Function Documentation

WLocalDateTime Wt::WLocalDateTime::currentDateTime ( const WLocale locale = WLocale::currentLocale())
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

Returns the date part.

Returns the date part.

See also
time()
WLocalDateTime Wt::WLocalDateTime::fromString ( const WString s,
const WLocale locale = WLocale::currentLocale() 
)
static

Parses a string to a time using the locale format.

See also
WLocale::dateTimeFormat()
bool Wt::WLocalDateTime::isNull ( ) const

Returns if this datetime is Null.

A null time is also invalid.

See also
isValid(), WDateTime()
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.

See also
setTime()
void Wt::WLocalDateTime::setDateTime ( const WDate date,
const WTime time 
)

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:

  • the time exists (on the day that the time changes from 2AM to 3AM the time 2.30AM does not exist)
  • the time is unambiguous (on the day that time changes from 3AM to 2AM. the time 2.30AM is not unambigous). In the latter case, setDateTime(const WDate&, const WTime&, bool) may still be used.
void Wt::WLocalDateTime::setDateTime ( const WDate date,
const WTime time,
bool  dst 
)

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)

Sets the time part.

If no valid date is set, the time is not set either.

See also
setDate()
WTime Wt::WLocalDateTime::time ( ) const

Returns the time part.

See also
setTime()
std::string Wt::WLocalDateTime::timeZone ( ) const

Returns the time zone.

See also
WLocale::setTimeZone()
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.

WString Wt::WLocalDateTime::toString ( ) const

Formats this datetime to a string using the locale format.

See also
WLocale::dateTimeFormat()
WString Wt::WLocalDateTime::toString ( const WString format) const

Formats this datetime to a string in a custom format.

See also
WLocale::dateTimeFormat()
WDateTime Wt::WLocalDateTime::toUTC ( ) const

Converts to UTC.

This is the reverse of WDateTime::toLocalTime()


Generated on Mon Sep 4 2017 for the C++ Web Toolkit (Wt) by doxygen 1.8.11