gregorian-calendar-format

2020-02-12

format utils for gregorian-calendar

gregorian-calendar-format


format gregorian-calendarinstance

gregorian-calendar-formatNPM downloadsBuild StatusCoverage StatusDependency Statusnode 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

LetterDate or Time ComponentPresentationExamples
GEra designatorTextAD
yYearYear1996; 96
YWeekYearWeekYear1996; 96
MMonth in yearMonthnumber of M matter. such as: MM:01 MMM:Jan MMMM: January
wWeek in yearNumber27
WWeek in monthNumber2
DDay in yearNumber189
dDay in monthNumber10
FDay of week in monthNumber2
EDay in weekTextnumber of E matter. such as: EEEE: Sunday, EEE: Sun
aAm/pm markerTextPM
HHour in day (0-23)Number0
kHour in day (1-24)Number24
KHour in am/pm (0-11)Number0
hHour in am/pm (1-12)Number12
mMinute in hourNumber30
sSecond in minuteNumber55
SMillisecondNumber978
x/zTime zoneGeneral time zonePacific Standard Time; PST; GMT-08:00
ZTime zoneRFC 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.

Repository

http://github.com/yiminghe/gregorian-calendar-format


上一篇:@beisen/storybook-react
下一篇:gregorian-calendar
相关教程
关注微信

扫码加入 JavaScript 社区

相关文章

首次访问,需要验证
微信扫码,关注即可
(仅需验证一次)

欢迎加入 JavaScript 社区

号内回复关键字:

回到顶部