Wt  3.2.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
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.
 WTime (int h, int m, int s=0, int ms=0)
 Construct a time given hour, minutes, seconds, and milliseconds.
bool setHMS (int h, int m, int s, int ms=0)
 Sets the time.
WTime addSecs (int s) const
 Adds seconds.
WTime addMSecs (int ms) const
 Adds milliseconds.
bool isNull () const
 Returns if this time is Null.
bool isValid () const
 Returns if this time is valid.
int hour () const
 Returns the hour (0-23).
int minute () const
 Returns the minutes (0-59).
int second () const
 Returns the seconds (0-59).
int msec () const
 Returns the milliseconds (0-999)
int secsTo (const WTime &t) const
 Returns the difference between two time values (in seconds).
int msecsTo (const WTime &t) const
 Returns the difference between two time values (in milliseconds).
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.
WString toString (const WString &format) const
 Formats this time to a string using a specified format.

Static Public Member Functions

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

Detailed Description

A value class that defines a clock time.

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

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.

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

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 time as indicated by the system clock of the server.

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()
int Wt::WTime::msecsTo ( const WTime t) const

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

This returns a value between -86400000 ms and 86400000 ms.

The result is negative if t is earlier than this.

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

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

This returns a value between -86400 s and 86400 s.

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.

h has range 0-23, 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
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

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 Mon Sep 24 2012 for the C++ Web Toolkit (Wt) by doxygen 1.8.1.2