Wt  3.3.9
Public Member Functions | Static Public Member Functions | List of all members
Wt::WTime Class Reference

A value class that defines a clock time. More...

#include <Wt/WTime>

Public Member Functions

 WTime ()
 Construct a Null time. More...
 
 WTime (int h, int m, int s=0, int ms=0)
 Construct a time given hour, minutes, seconds, and milliseconds. More...
 
bool setHMS (int h, int m, int s, int ms=0)
 Sets the time. More...
 
WTime addSecs (int s) const
 Adds seconds. More...
 
WTime addMSecs (int ms) const
 Adds milliseconds. More...
 
bool isNull () const
 Returns if this time is Null. More...
 
bool isValid () const
 Returns if this time is valid.
 
int hour () const
 Returns the hour.
 
int minute () const
 Returns the minutes (0-59).
 
int second () const
 Returns the seconds (0-59).
 
int msec () const
 Returns the milliseconds (0-999)
 
long secsTo (const WTime &t) const
 Returns the difference between two time values (in seconds). More...
 
long msecsTo (const WTime &t) const
 Returns the difference between two time values (in milliseconds). More...
 
bool operator< (const WTime &other) const
 Compares two time values.
 
bool operator<= (const WTime &other) const
 Compares two time values.
 
bool operator> (const WTime &other) const
 Compares two time values.
 
bool operator>= (const WTime &other) const
 Compares two time values.
 
bool operator== (const WTime &other) const
 Compares two time values.
 
bool operator!= (const WTime &other) const
 Compares two time values.
 
WString toString () const
 Formats this time to a string using a default format. More...
 
WString toString (const WString &format) const
 Formats this time to a string using a specified format. More...
 

Static Public Member Functions

static WTime fromString (const WString &s)
 Parses a string to a time using a default format. More...
 
static WTime fromString (const WString &s, const WString &format)
 Parses a string to a time using a specified format. More...
 
static WTime currentTime ()
 Reports the current client date. More...
 
static WTime currentServerTime ()
 Reports the current server time. More...
 

Detailed Description

A value class that defines a clock time.

A clock time represents the time of day (usually 0 to 24 hour), up to millisecond precision.

As of version %3.3.1, the time class itself will no longer limit times to the 24-hour range, but will allow any time (duration), including negative values.

See also
WDate, WDateTime

Constructor & Destructor Documentation

Wt::WTime::WTime ( )

Construct a Null time.

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

See also
isValid(), isNull()
Wt::WTime::WTime ( int  h,
int  m,
int  s = 0,
int  ms = 0 
)

Construct a time given hour, minutes, seconds, and milliseconds.

m and s have range 0-59, and ms has range 0-999. A duration can be positive or negative depending on the sign of h.

When the time is invalid, isValid() is set to false.

Member Function Documentation

WTime Wt::WTime::addMSecs ( int  ms) const

Adds milliseconds.

Returns a time that is ms milliseconds later than this time. Negative values for ms will result in a time that is as many milliseconds earlier.

WTime Wt::WTime::addSecs ( int  s) const

Adds seconds.

Returns a time that is s seconds later than this time. Negative values for s will result in a time that is as many seconds earlier.

WTime Wt::WTime::currentServerTime ( )
static

Reports the current server time.

This method returns the local time on the server.

See also
WDateTime::currentDateTime(), WLocalDateTime::currentServerDateTime()
WTime Wt::WTime::currentTime ( )
static

Reports the current client date.

This method uses browser information to retrieve the time that is configured in the client.

See also
WLocalDateTime::currentDate()
WTime Wt::WTime::fromString ( const WString s)
static

Parses a string to a time using a default format.

The default format is "hh:mm:ss". For example, a time specified as:

"22:55:15"

will be parsed as a time that equals a time constructed as:

WTime d(22,55,15);

When the time could not be parsed or is not valid, an invalid time is returned (for which isValid() returns false).

See also
fromString(const WString& s, const WString& format), isValid()
WTime Wt::WTime::fromString ( const WString s,
const WString format 
)
static

Parses a string to a time using a specified format.

The format follows the same syntax as used by toString(const WString& format).

When the time could not be parsed or is not valid, an invalid time is returned (for which isValid() returns false).

See also
toString(const WString&) const
bool Wt::WTime::isNull ( ) const

Returns if this time is Null.

A null time is also invalid.

See also
isValid(), WTime()
long Wt::WTime::msecsTo ( const WTime t) const

Returns the difference between two time values (in milliseconds).

The result is negative if t is earlier than this.

long Wt::WTime::secsTo ( const WTime t) const

Returns the difference between two time values (in seconds).

The result is negative if t is earlier than this.

bool Wt::WTime::setHMS ( int  h,
int  m,
int  s,
int  ms = 0 
)

Sets the time.

m and s have range 0-59, and ms has range 0-999.

When the time is invalid, isValid() is set to false.

WString Wt::WTime::toString ( ) const

Formats this time to a string using a default format.

The default format is "hh:mm:ss".

WString Wt::WTime::toString ( const WString format) const

Formats this time to a string using a specified format.

The format is a string in which the following contents has a special meaning.

CodeMeaning Example (for 14:06:23.045)
hThe hour without leading zero (0-23 or 1-12 for AM/PM display) 14 or 2
hhThe hour with leading zero (00-23 or 01-12 for AM/PM display) 14 or 02
HThe hour without leading zero (0-23) 14
HHThe hour with leading zero (00-23) 14
+ followed by (h/hh/H/HH)The sign of the hour (+/-) +
mThe minutes without leading zero (0-59) 6
mmThe minutes with leading zero (00-59) 06
sThe seconds without leading zero (0-59) 23
ssThe seconds with leading zero (00-59) 23
zThe milliseconds without leading zero (0-999) 45
zzzThe millisecons with leading zero (000-999) 045
AP or Ause AM/PM display: affects h or hh display and is replaced itself by AM/PM PM
ap or ause am/pm display: affects h or hh display and is replaced itself by am/pm pm
Zthe timezone in RFC 822 format (e.g. -0800) +0000

Any other text is kept literally. String content between single quotes (') are not interpreted as special codes. Inside a string, a literal quote may be specifed using a double quote ('').

Examples of format and result:

FormatResult (for 22:53:13.078)
hh:mm:ss.zzz22:53:13.078
hh:mm:ss AP10:53:13 PM
See also
fromString(const WString& value, const WString& format)

Generated on Tue Nov 21 2017 for the C++ Web Toolkit (Wt) by doxygen 1.8.11