Giter Club home page Giter Club logo

simple-date-format's Introduction

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/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

simple-date-format's People

Contributors

riversun avatar dependabot[bot] avatar codacy-badger avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.