Formerly ryannhg/date-format. Search finds this package by either name.
A reliable way to format dates and times with Elm.
If our users don't speak English, printing out "Monday" or "Tuesday" might not be a great fit.
Thanks to a great recommendation, date-format now supports multilingual output!
All you need to do is provide your own options, and format will use your preferences instead:
For a complete example, check out the FormatWithOptions.elm in the examples folder.
These are the available tokens to help you format dates.
Get the numeric value of the month.
Examples: 1, 2, 3, ... 11, 12
Get the numeric value of the month, with a suffix at the end.
Examples: 1st, 2nd, 3rd, ... 11th, 12th
Get the numeric value of the month, fixed to two places.
Examples: 01, 02, 03, ... 11, 12
Get the name of the month, but abbreviated (abbreviation function comes from the language settings)
Examples: Jan, Feb, Mar, ... Nov, Dec
Get the full name of the month.
Examples: January, February, ... December
Get the numeric value of the day of the month.
Examples: 1, 2, 3, ... 30, 31
Get the numeric value of the day of the month, with a suffix at the end.
Examples: 1st, 2nd, 3rd, ... 30th, 31st
Get the numeric value of the day of the month, fixed to two places.
Examples: 01, 02, 03, ... 30, 31
Get the numeric value of the day of the year.
Examples: 1, 2, 3, ... 364, 365
Get the numeric value of the day of the year, with a suffix at the end.
Examples: 1st, 2nd, 3rd, ... 364th, 365th
Get the numeric value of the day of the year, fixed to three places.
Examples: 001, 002, 003, ... 364, 365
Get the numeric value of the day of the week.
Examples: 0, 1, 2, ... 5, 6
Get the numeric value of the day of the week, with a suffix at the end.
Examples: 0th, 1st, 2nd, ... 5th, 6th
Gets the name of the day of the week, but just the first two letters.
Examples: Su, Mo, Tu, ... Fr, Sa
Gets the full name of the day of the week.
Examples: Sunday, Monday, ... Friday, Saturday
Get the year, but just the last two letters.
Examples: 70, 71, ... 29, 30
Get the year.
Examples: 1970, 1971, ... 2018, ... 9999, ...
Get the numeric value for the quarter of the year.
Examples: 1, 2, 3, 4
Get the numeric value for the quarter of the year, with a suffix.
Examples: 1st, 2nd, 3rd, 4th
Get the numeric value for the week of the year.
Examples: 1, 2, 3, ... 51, 52
Get the numeric value for the week of the year, with a suffix at the end.
Examples: 1st, 2nd, 3rd, ... 51st, 52nd
Get the numeric value for the week of the year, fixed to two places.
Examples: 01, 02, 03, ... 51, 52
Get the AM / PM value of the hour, in uppercase.
Examples: AM, PM
Get the AM / PM value of the hour, in uppercase.
Examples: am, pm
Get the hour of the 24-hour day.
Examples: 0, 1, 2, ... 22, 23
Get the hour of the 24-hour day, fixed to two places.
Examples: 00, 01, 02, ... 22, 23
Get the hour of the 12-hour day.
Examples: 0, 1, 2, ... 11, 12
Get the hour of the 12-hour day, fixed to two places.
Examples: 00, 01, 02, ... 11, 12
Get the hour of the 24-hour day, starting from one.
Examples: 1, 2, ... 23, 24
Get the hour of the 24-hour day, starting from one, fixed to two places.
Examples: 01, 02, ... 23, 24
Get the minute of the hour.
Examples: 0, 1, 2, ... 58, 59
Get the minute of the hour, fixed to two places.
Examples: 00, 01, 02, ... 58, 59
Get the second of the minute.
Examples: 0, 1, 2, ... 58, 59
Get the second of the minute, fixed to two places.
Examples: 00, 01, 02, ... 58, 59
Get the milliseconds of the second.
Examples: 0, 1, 2, ... 998, 999
Get the milliseconds of the second, fixed to three places.
Examples: 000, 001, 002, ... 998, 999
This function takes in a list of tokens,
Zone, andPosixto create your formatted string!Let's say
ourPosixValueis November 15, 1993 at 15:06.