Format Datetime Functions
The following is the sample JSON for all the examples
data = {
"company_name": "Nakatomi Trading Corp",
"total_amount": 82542.56,
"date": "2021-09-30",
"items": [
{
"name": "Brand Guide",
"man_hour": 2,
"unit": "hour",
"unit_price": 120.0,
"item_total": 240.0
},
{
"name": "Software Development",
"man_hour": 17,
"unit": "hour",
"unit_price": 20.0,
"item_total": 340.0
},
{
"name": "Landing Page Design",
"man_hour": 5,
"unit": "hour",
"unit_price": 20.0,
"item_total": 80.0
}
]
}
format
It formats a string(datetime) according to a format and returns a formatted string.
Usage
format(`datestring`, `type`, `srcformat`, `destformat`)
Parameters
Parameter | Type | Description |
datestring | string | A datetime string |
type | string | use “datetime” |
srcformat | string | Parse the specified datestring as srcformat |
destformat | string | format the string as destformat |
- Visit momentjs for details for the srcformat or destformat
- Moment.js cheatsheet
Example
{{format(data.date,"datetime","YYYY-MM-DD","YYYY-MM-DD HH:mm:ss")}}
Output
2021-09-30 00:00:00
Use Moment library to format
Use momentjs in the expression
Please visit momentjs for details
Example
{{ moment().format('MMMM Do YYYY, h:mm:ss a') }}
Output
August 16th 2021, 12:00:33 pm