Example: date formatting
All examples below use:
// UTC
const date = new Date(2018, 2, 15, 12, 34, 56, 789);
// Formats that include time will use these 3 zones
const zones = [ 'America/New_York', 'Europe/London', 'Asia/Tokyo' ];
Dates
const cldr = framework.get('en');
// UTC
const date = new Date(2018, 2, 15, 12, 34, 56, 789);
// Formats that include time will use these 3 zones
const zones = [ 'America/New_York', 'Europe/London', 'Asia/Tokyo' ];
log(cldr.Calendars.formatDate({ date }, { date: 'short' }));
3/15/18
log(cldr.Calendars.formatDate({ date }, { date: 'medium' }));
Mar 15, 2018
log(cldr.Calendars.formatDate({ date }, { date: 'long' }));
March 15, 2018
log(cldr.Calendars.formatDate({ date }, { date: 'full' }));
Thursday, March 15, 2018
Times
zones.forEach(zoneId =>
log(cldr.Calendars.formatDate({ date, zoneId }, { time: 'short' })));
12:34 PM 4:34 PM 1:34 AM
zones.forEach(zoneId =>
log(cldr.Calendars.formatDate({ date, zoneId }, { time: 'medium' })));
12:34:56 PM 4:34:56 PM 1:34:56 AM
zones.forEach(zoneId =>
log(cldr.Calendars.formatDate({ date, zoneId }, { time: 'long' })));
12:34:56 PM EDT 4:34:56 PM GMT 1:34:56 AM GMT+9
zones.forEach(zoneId =>
log(cldr.Calendars.formatDate({ date, zoneId }, { time: 'full' })));
12:34:56 PM Eastern Daylight Time 4:34:56 PM Greenwich Mean Time 1:34:56 AM Japan Standard Time
Dates and times
zones.forEach(zoneId =>
log(cldr.Calendars.formatDate({ date, zoneId }, { datetime: 'short' )}));
3/15/18, 12:34 PM 3/15/18, 4:34 PM 3/16/18, 1:34 AM
zones.forEach(zoneId =>
log(cldr.Calendars.formatDate({ date, zoneId }, { datetime: 'medium' })));
Mar 15, 2018, 12:34:56 PM Mar 15, 2018, 4:34:56 PM Mar 16, 2018, 1:34:56 AM
zones.forEach(zoneId =>
log(cldr.Calendars.formatDate({ date, zoneId }, { datetime: 'long' })));
March 15, 2018 at 12:34:56 PM EDT March 15, 2018 at 4:34:56 PM GMT March 16, 2018 at 1:34:56 AM GMT+9
zones.forEach(zoneId =>
log(cldr.Calendars.formatDate({ date, zoneId }, { datetime: 'full' })));
Thursday, March 15, 2018 at 12:34:56 PM Eastern Daylight Time Thursday, March 15, 2018 at 4:34:56 PM Greenwich Mean Time Friday, March 16, 2018 at 1:34:56 AM Japan Standard Time
Date skeletons
log(cldr.Calendars.formatDate({ date }, { skeleton: 'yMd' }));
3/15/2018
log(cldr.Calendars.formatDate({ date }, { skeleton: 'yMMMd' }));
Mar 15, 2018
log(cldr.Calendars.formatDate({ date }, { skeleton: 'yMMMMd' }));
March 15, 2018
log(cldr.Calendars.formatDate({ date }, { skeleton: 'EEEEyMMMMd' }));
Thursday, March 15, 2018
Time skeletons
zones.forEach(zoneId =>
log(cldr.Calendars.formatDate({ date, zoneId }, { skeleton: 'hm' })));
12:34 PM 4:34 PM 1:34 AM
zones.forEach(zoneId =>
log(cldr.Calendars.formatDate({ date, zoneId }, { skeleton: 'hmsz' })));
12:34:56 PM EDT 4:34:56 PM GMT 1:34:56 AM GMT+9
zones.forEach(zoneId =>
log(cldr.Calendars.formatDate({ date, zoneId }, { skeleton: 'hmszzzz' })));
12:34:56 PM Eastern Daylight Time 4:34:56 PM Greenwich Mean Time 1:34:56 AM Japan Standard Time
zones.forEach(zoneId =>
log(cldr.Calendars.formatDate({ date, zoneId }, { skeleton: 'hmsVVVV' })));
12:34:56 PM New York Time 4:34:56 PM London Time 1:34:56 AM Tokyo Time
zones.forEach(zoneId =>
log(cldr.Calendars.formatDate({ date, zoneId }, { skeleton: 'hmsvvvv' })));
12:34:56 PM Eastern Time 4:34:56 PM GMT 1:34:56 AM Japan Time
Date time skeletons
zones.forEach(zoneId =>
log(cldr.Calendars.formatDate({ date, zoneId }, { skeleton: 'yMdhm' })));
3/15/2018, 12:34 PM 3/15/2018, 4:34 PM 3/16/2018, 1:34 AM
zones.forEach(zoneId =>
log(cldr.Calendars.formatDate({ date, zoneId }, { skeleton: 'yMMMdhmsz' })));
Mar 15, 2018, 12:34:56 PM EDT Mar 15, 2018, 4:34:56 PM GMT Mar 16, 2018, 1:34:56 AM GMT+9
zones.forEach(zoneId =>
log(cldr.Calendars.formatDate({ date, zoneId }, { skeleton: 'EyMMMMdhmszzzz' })));
Thu, March 15, 2018 at 12:34:56 PM Eastern Daylight Time Thu, March 15, 2018 at 4:34:56 PM Greenwich Mean Time Fri, March 16, 2018 at 1:34:56 AM Japan Standard Time
zones.forEach(zoneId =>
log(cldr.Calendars.formatDate({ date, zoneId }, { skeleton: 'yMMMdhmsVVVV' })));
Mar 15, 2018, 12:34:56 PM New York Time Mar 15, 2018, 4:34:56 PM London Time Mar 16, 2018, 1:34:56 AM Tokyo Time
zones.forEach(zoneId =>
log(cldr.Calendars.formatDate({ date, zoneId }, { skeleton: 'yMMMMdhmsvvvv' })));
March 15, 2018 at 12:34:56 PM Eastern Time March 15, 2018 at 4:34:56 PM GMT March 16, 2018 at 1:34:56 AM Japan Time