Wt
4.10.3
|
A value class that defines a clock time. More...
#include <Wt/WTime.h>
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. | |
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). | |
long | 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 | currentTime () |
Reports the current client date. | |
static WTime | currentServerTime () |
Reports the current server time. | |
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.
Wt::WTime::WTime | ( | ) |
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
.
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.
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.
Reports the current server time.
This method returns the local time on the server.
Reports the current client date.
This method uses browser information to retrieve the time that is configured in the client.
Parses a string to a time using a default format.
The default format is "hh:mm:ss". For example, a time specified as:
will be parsed as a time that equals a time constructed as:
When the time could not be parsed or is not valid, an invalid time is returned (for which isValid() returns false).
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).
bool Wt::WTime::isNull | ( | ) | const |
Returns the difference between two time values (in milliseconds).
The result is negative if t is earlier than this.
Returns the difference between two time values (in seconds).
The result is negative if t is earlier than this.
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".
Formats this time to a string using a specified format.
The format
is a string in which the following contents has a special meaning.
Code | Meaning | Example (for 14:06:23.045) |
h | The hour without leading zero (0-23 or 1-12 for AM/PM display) | 14 or 2 |
hh | The hour with leading zero (00-23 or 01-12 for AM/PM display) | 14 or 02 |
H | The hour without leading zero (0-23) | 14 |
HH | The hour with leading zero (00-23) | 14 |
+ followed by (h/hh/H/HH) | The sign of the hour (+/-) | + |
m | The minutes without leading zero (0-59) | 6 |
mm | The minutes with leading zero (00-59) | 06 |
s | The seconds without leading zero (0-59) | 23 |
ss | The seconds with leading zero (00-59) | 23 |
z | The milliseconds without leading zero (0-999) | 45 |
zzz | The millisecons with leading zero (000-999) | 045 |
AP or A | use AM/PM display: affects h or hh display and is replaced itself by AM/PM | PM |
ap or a | use am/pm display: affects h or hh display and is replaced itself by am/pm | pm |
Z | the 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. LabelOption::Inside a string, a literal quote may be specifed using a double quote ('').
Examples of format and result:
Format | Result (for 22:53:13.078) |
hh:mm:ss.zzz | 22:53:13.078 |
hh:mm:ss AP | 10:53:13 PM |