|
Wt
3.3.0
|
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. | |
A value class that defines a clock time.
A clock time represents the time of day (0 to 24 hour), up to millisecond precision.
| Wt::WTime::WTime | ( | ) |
| 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.
| 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.
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).
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 |
| 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".
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 |
| 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 |
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:
| Format | Result (for 22:53:13.078) |
| hh:mm:ss.zzz | 22:53:13.078 |
| hh:mm:ss AP | 10:53:13 PM |
1.7.5.1