0.0.2 • Published 3 years ago

strftime-js v0.0.2

Weekly downloads
2
License
MIT
Repository
github
Last release
3 years ago

strftime-js

Method that enable formatted output(like strftime in Python) from date instance.

Installation

Use yarn

yarn add strftime-js

or npm

npm install strftime-js

Usage

Patch method to instance

import { patchInstance } from 'data-formatter'

const instance = new Date()
console.log(patchInstance(instance).toFormatted('Today is %x')) // -> Today is 1/1/2020

Patch method to constructor

import { patch } from 'data-formatter'

patch()
const instance = new Date()
console.log(instance.toFormatted('Today is %x')) // -> Today is 1/1/2020

Reference

CodeMeaningExample
%aWeekday as abbreviated name.Mon
%AWeekday as full name.Monday
%wWeekday as a decimal number, where 0 is Sunday and 6 is Saturday.1
%dDay of the month.30
%bMonth as abbreviated name.Sep
%BMonth as full name.September
%mMonth as a decimal number, where 0 is January and 11 is December.9
%yYear without century as a decimal number.13
%YYear with century as a decimal number.2013
%HHour (24-hour clock) as a decimal number.07
%IHour (12-hour clock) as a decimal number.07
%pLocale’s equivalent of either AM or PM.AM
%MMinute as a decimal number.06
%SSecond as a decimal number.05
%jDay of the year as a decimal number.273
%UWeek number of the year (Sunday as the first day of the week) as a decimal number. All days in a new year preceding the first Sunday are considered to be in week 0.39
%WWeek number of the year (Monday as the first day of the week) as a decimal number. All days in a new year preceding the first Monday are considered to be in week 0.39
%cLocale’s appropriate date and time representation.Mon Sep 30 07:06:05 2013
%xLocale’s appropriate date representation.09/30/13
%XLocale’s appropriate time representation.07:06:05
%%A literal '%' character.%