gregorian-calendar-format
v4.1.3
Published
format utils for gregorian-calendar
Downloads
5,877
Maintainers
Readme
gregorian-calendar-format
format gregorian-calendar instance
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
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.