Get unlimited public & private packages + package-based permissions with npm Pro.Get started »

gregorian-calendar-format

4.1.3 • Public • Published

gregorian-calendar-format


format gregorian-calendar instance

gregorian-calendar-format NPM downloads Build Status Coverage Status Dependency Status node version

use on node

var GregorianCalendarFormat = require('gregorian-calendar-format');
var GregorianCalendar = require('gregorian-calendar');
var gregorianCalendar = new GregorianCalendar();
gregorianCalendar.set(2013, GregorianCalendar.JULY, 9);
var df = new GregorianCalendarFormat('yyyy-MM-dd');
console.log(df.format(gregorianCalendar));
df = new GregorianCalendarFormat('yy-MM-dd');
console.log(df.format(gregorianCalendar));

API

Constructor GregorianCalendarFormat(pattern: String, locale: Object)

  • pattern: pattern string used to format or parse
Letter Date or Time Component Presentation Examples
G Era designator Text AD
y Year Year 1996; 96
Y WeekYear WeekYear 1996; 96
M Month in year Month number of M matter. such as: MM:01 MMM:Jan MMMM: January
w Week in year Number 27
W Week in month Number 2
D Day in year Number 189
d Day in month Number 10
F Day of week in month Number 2
E Day in week Text number of E matter. such as: EEEE: Sunday, EEE: Sun
a Am/pm marker Text PM
H Hour in day (0-23) Number 0
k Hour in day (1-24) Number 24
K Hour in am/pm (0-11) Number 0
h Hour in am/pm (1-12) Number 12
m Minute in hour Number 30
s Second in minute Number 55
S Millisecond Number 978
x/z Time zone General time zone Pacific Standard Time; PST; GMT-08:00
Z Time zone RFC 822 time zone -0800

such as "yyyy-MM-dd'日'" will parse and format "2013-11-12日" "2013-01-02日". (content inside '' will preserve)

  • locale: require('gregorian-calendar-format/locale/en_US') or require('gregorian-calendar-format/locale/zh_CN') specify text when render localize date time string.

String GregorianCalendarFormat.prototype.format(calendar: GregorianCalendar)

format an instance of GregorianCalendar according to pattern

GregorianCalendar GregorianCalendarFormat.prototype.parse(dateString: String, {locale: object})

parse a dateString to an instance of GregorianCalendar according to pattern, it's better to specify calendarLocale, such as

df.parse('2013-11-12', {locale: require('gregorian-calendar/lib/locale/zh_CN'}));

GregorianCalendarFormat GregorianCalendarFormat.getDateTimeInstance(dateStyle, timeStyle, locale)

get a predefine GregorianCalendarFormat instance

  • dateStyle: enum of predefined date style, enums:
  • en_US:
    • GregorianCalendarFormat.Style.FULL presents EEEE, MMMM d, yyyy
    • GregorianCalendarFormat.Style.LONG presents MMMM d, yyyy
    • GregorianCalendarFormat.Style.MEDIUM presents MMM d, yyyy
    • GregorianCalendarFormat.Style.SHORT presents M/d/yy
  • zh_CN:
    • GregorianCalendarFormat.Style.FULL presents "yyyy'年'M'月'd'日' EEEE"
    • GregorianCalendarFormat.Style.LONG presents "yyyy'年'M'月'd'日'"
    • GregorianCalendarFormat.Style.MEDIUM presents "yyyy-M-d"
    • GregorianCalendarFormat.Style.SHORT presents "yy-M-d"
  • timeStyle: enum of predefined date style, enums:
  • en_US:
    • GregorianCalendarFormat.Style.FULL presents 'h:mm:ss a 'GMT'Z'
    • GregorianCalendarFormat.Style.LONG presents 'h:mm:ss a'
    • GregorianCalendarFormat.Style.MEDIUM presents 'h:mm:ss a'
    • GregorianCalendarFormat.Style.SHORT presents 'h:mm a'
  • zh_CN:
    • GregorianCalendarFormat.Style.FULL presents "ahh'时'mm'分'ss'秒' 'GMT'Z"
    • GregorianCalendarFormat.Style.LONG presents "ahh'时'mm'分'ss'秒'"
    • GregorianCalendarFormat.Style.MEDIUM presents "H:mm:ss"
    • GregorianCalendarFormat.Style.SHORT presents "ah:mm"
  • locale: require('gregorian-calendar-format/locale/en_US') or require('gregorian-calendar-format/locale/zh_CN') specify text when render localize date time string.

License

gregorian-calendar-format is released under the MIT license.

Install

npm i gregorian-calendar-format

DownloadsWeekly Downloads

535

Version

4.1.3

License

MIT

Last publish

Collaborators

  • avatar