Miss any of our Open RFC calls?Watch the recordings here! »

@riversun/simple-date-format

1.1.4 • Public • Published

simple-date-format

npm version CircleCI codecov Codacy Badge License: MIT

Simple Date Formater for JavaScript. It allows for formatting date → text .

You can easily format date with specific patterns like as follows.

yyyyMMdd'T'HHmmssXX20180717T120856+0900

live demo is here

install

use node.js/npm

install module

npm install @riversun/simple-date-format

import module

import SimpleDateFormat from "@riversun/simple-date-format";
 

or

require module

const SimpleDateFormat = require('@riversun/simple-date-format');
 

use with <script>tag from CDN

<script src="https://cdn.jsdelivr.net/npm/@riversun/simple-date-format@1.1.2/lib/simple-date-format.js"></script>

usage

const date = new Date('2018/07/17 12:08:56');
const sdf = new SimpleDateFormat();
console.log(sdf.formatWith("yyyy-MM-dd'T'HH:mm:ssXXX", date));//to be "2018-07-17T12:08:56+09:00"
const date = new Date('2018/07/17 12:08:56');
const sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX");
console.log(sdf.format(date));//to be "2018-07-17T12:08:56+09:00"

Pattern of the date

The following examples show how date and time patterns are interpreted. The given date and time are 2018-07-17 12:08:56 local time in Tokyo/Japan time zone.

Letter(s) Date or Time Component Examples
yyyy Year 2018
yy 18
M Month in year 7
MM 07
MMM Month name Jul
d Day in month 17
dd 17
a Am/pm marker PM
H Hour in day (0-23) 12
HH 12
E day of week Tue
h Hour in am/pm (1-12) 12
hh 12
m Minute in hour 8
mm 08
s Second in minute 56
ss 56
SSS Millisecond 789
Z Timezone(RFC822) +0900
X Timezone(ISO8601) +09
XX +0900
XXX +09:00
' ' Strings(Escaped)
'' Single Quote

Examples

Format String Example
yyyyMMdd'T'HHmmssXX
(ISO 8601)
20180717T120856+0900
yyyy-MM-dd'T'HH:mm:ssXXX
(ISO 8601)
2018-07-17T12:08:56+09:00
E, dd MMM yyyy HH:mm:ss Z Tue, 17 Jul 2018 12:08:56 +0900
yyyy.MM.dd 'at' hh:mm:ss Z 2018.07.17 at 12:08:56 +0900
EEE, MMM d, ''yy Tue, Jul 17, '18
h:mm a 12:08 PM
hh 'o''''clock' a, X 12 o'clock PM, +09
yyyy年M月d日 H時m分s秒 2018年7月17日 12時8分56秒
yyyy年MM月dd日 HH時mm分ss秒 2018年07月17日 12時08分56秒
yyyyMMddHHmmssSSS 20180717120856789

Keywords

none

Install

npm i @riversun/simple-date-format

DownloadsWeekly Downloads

17

Version

1.1.4

License

MIT

Unpacked Size

17.1 kB

Total Files

8

Last publish

Collaborators

  • avatar