Culture specific date/time and number formatting and parsing based on ECMAScript Internationalization API (Intl).
Used for localized calendars, date fields and number fields in CxJS.
This module is available in four formats:
- CommonJS:
dist/intl-io.js - ES Module:
dist/intl-io.module.js - Modern ES Module:
dist/intl-io.modern.js - UMD:
dist/intl-io.umd.js
$ npm install intl-io --save
import{DateTimeCulture,NumberCulture}from'intl-io';letdateCulture=newDateTimeCulture('es');dateCulture.format(newDate(),'yyyyMMdd');//28/08/2019dateCulture.format(newDate(),'yyyyMMMdd');//28 ago. 2019dateCulture.format(newDate(),'yyyyMMdd');//28 de agosto de 2019dateCulture.format(newDate(),'yyyyMMddDDD');//mié., 28 de agosto de 2019letdate=culture.parse('mié., 28 de agosto de 2019',{loose: true});//Aug 28, 2019letnumberCulture=newNumberCulture('de');letformatter=numberCulture.getFormatter({style: 'currency',currency: 'EUR',});letcurrency=formatter.format(5555.5);//5.555,50 €letnumber=numberCulture.parse('5.555,5');//5555.5For number formatting options look at https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat.
Some parts support different length. Four digits means full name, three digits is a long form, two digits is medium and one digit is short form.
YYYY- full year (e.g. 2019)YY- short year (e.g. 19)
MMMM- long month name (e.g. August)MMM- short month name (e.g. Aug)MM- two digit month (e.g. 08)M- numeric month (e.g. 8)
DDDD- full day name (e.g. Monday)DDD- short day name (e.g. Mon)DD- short day name (e.g. Mo)D- short day name (e.g. M)
| Format | Description | Result |
|---|---|---|
yyyyMMdd | Short date | 09/07/2019 |
yyyyMMMdd | Medium date | Sep 07, 2019 |
HHmm | Short time | 09:35 PM |
HHmmN | Short time | 21:35 |
yyyyMMMddHHmm | Full date time | Sep 07, 2019 09:35 PM |
| Specifier | Part |
|---|---|
y, Y | year |
M | month |
D | day name |
d | day |
h, H | hours |
m, i | minutes |
s, S | seconds |
a, A | hour12 AM/PM |
p, P | hour12 AM/PM |
n, N | hour24 |
t, T | timezone |
u, U | UTC timezone |
z, Z | UTC timezone |
For detailed date formatting options look at https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat.
MIT © Codaxy