Time Module
Overview
The Time Module provides methods and variables which work with dates.
Refer to Date Modules for similar methods which work with with date values.
FORMATTING TIME VALUES
The Time Module uses JavaScript moment
library internally, thus you can use any of the Momentjs Formatting options.
Each time token has a single or double token, with the double token being used to display leading zeros.
Formatting Time Values
Tokens are case-sensitive.
Input | Example | Description |
---|---|---|
H HH | 0..23 | Hours (24 hour time) |
h hh | 1..12 | Hours (12 hour time used with a A .) |
k kk | 1..24 | Hours (24 hour time from 1 to 24) |
a A | am pm | Post or ante meridiem (Note the one character a p are also considered valid) |
m mm | 0..59 | Minutes |
s ss | 0..59 | Seconds |
S SS SSS ... SSSSSSSSS | 0..999999999 | Fractional seconds |
Z ZZ | +12:00 | Offset from UTC as +-HH:mm , +-HHmm , or Z |
Example
If you wish to display time value with hour and minute in 24 hour format, separated by a colon:
character, you would use <%- date.now('H:mm') %>
Methods
namespace:
time
The following are the methods available in the Time Module, and they can be used in any Templating
template, no additional configuration required.
now
now(format? : string = '') : string
Returns a string representation current time.
-
format?
- Desired time format. If not supplied, it will use the Time Format value inTemplating
Plugin Settings -
-> result
- Returns formatted time string
Examples
The following example returns the current time, using default values
<%- time.now() %>
The following example returns current time using custom format, using 12hr format.
<%- time.now("h:mm") %> // returns 7:22 (no leading zero)
The following example returns current time using custom format, using 24hr format, each displayed with leading zeros
<%- time.now("HH:mm") %> // returns 07:22
The following example returns curren time in 12hr format, with lowercase am/pm
<%- time.now("hh:mm a") %> // returns 07:22 am
The following example returns curren time in 12hr format, with uppercase AM/PM
<%- time.now("hh:mm A") %> // returns 07:22 AM
currentTime
currentTime(format? : string = '') : string
Returns a string representation current time.
-
format?
- Desired time format. If not supplied, it will use the Time Format inTemplating
Plugin Settings -
-> result
- Returns formatted time string
Examples
The following example returns the current time, using default values
<%- time.currentTime() %>
The following example returns current time using custom format
<%- time.currentTime("h:mm") %>
The following example uses the currentTime
helper
<%- currentTime() %>
format
format(format : string = '', pivotDate? : string = '') : string
Formats pivotDate
using supplied format
.
Note: Also available as a helper method
-
format?
- A valid time format string -
pivotDate?
- Desired date to format. If not supplied, it will use current date. -
-> result
- Returns formatted time string
TIP
Refer to Momentjs Formatting for available formatting options.
convertTime12to24
convertTime12to24(time12hr: string = '')
Convert 12-hour time to 24-hour time