New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

datetime-str

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

datetime-str

Converts Date object to string with some format

latest
npmnpm
Version
1.0.2
Version published
Maintainers
1
Created
Source

Installation

Open your project's directory and execute next command:

npm install --save datetime-str

Including to your project

In order to use package in your project it should be assigned to the variable

const datetime_str = require('datetime-str');

Next command will create variable datetime_str that will hold module

Structure

  • monthNames - Names of months starting from January
  • monthNamesPart - Contains first 3 symbols of each month name
  • dayNames - Names of days of week starting from Sunday
  • dayNamesPart - Contains first 3 symbols of each day name
  • formats - Contains list of standart patterns
  • format(pattern, date) - Creates string by pattern using given date

API

monthNames - names of months from January

Type: array

Length: 12

Values:

[
    'January',
    'February',
    'March',
    'April',
    'May',
    'June',
    'July',
    'August',
    'September',
    'October',
    'November',
    'December'
]

monthNamesPart - first 3 symbols of months names

Type: array

Length: 12

Values:

[
    'Jan',
    'Feb',
    'Mar',
    'Apr',
    'May',
    'Jun',
    'Jul',
    'Aug',
    'Sep',
    'Oct',
    'Nov',
    'Dec'
]

dayNames - Names of days of week starting from Sunday

Type: array

Length: 7

Values:

[
    'Sunday',
    'Monday',
    'Tuesday',
    'Wednessday',
    'Thursday',
    'Friday',
    'Saturday'
]

dayNamesPart - first 3 symbols of day names

Type: array

Length: 7

Values:

[
    'Sun',
    'Mon',
    'Tue',
    'Wed',
    'Thu',
    'Fri',
    'Sat'
]

formats - Contains list of standart patterns

Type: object

Keys: default, en, ru

default format

{
    'full'       : '{yyyy mmmm d HH:MM:SS} UTC {UTC}',
    'datetime'   : '{yyyy-mm-dd HH:MM:SS}',
    'datetime12' : '{yyyy-mm-dd HH12:MM:SS AMPM}',

    'date'       : '{yyyy-mm-dd}',
    'time'       : '{HH:MM:SS}',
    'time12'     : '{HH12:MM:SS AMPM',

    'precise'    : 'SS.LL' 
}

us format

{
    'full'       : '{mmmm d yyyy HH:MM:SS} UTC {UTC}',
    'datetime'   : '{mm/dd/yyyy HH:MM:SS}',
    'datetime12' : '{mm/dd/yyyy HH12:MM:SS ampm}',
    'date'       : '{mm/dd/yyyy}'
}

ru format

{
    'full'       : '{yyyy mmmm d HH:MM:SS} UTC {UTC}',
    'datetime'   : '{dd.mm.yyyy HH:MM:SS}',
    'datetime12' : '{dd.mm.yyyy HH12:MM:SS ampm}',
    'date'       : '{dd.mm.yyyy}'
}

Formating

format(pattern, date) - Formats date using pattern

pattern - string

date - standart Date object

Starting with patterns

Pattern is a simple string that can contains any symbols

To designate where formated date should be placed {}(curly braces) are used

Simple pattern that shows current time will be:

'Current time is {HH} hours {MM} minutes {SS} seconds'

It is possible to use multiple keys within {}(curly braces)

'Current time: {HH:MM:SS}`

They can be splited by any not alpha-numeric symbols

List of possible keys

Date - numbers

yyyy - full year. Example: 2002

yy - two-digit year with leading zero. Example: 02

y - two-digit year without leading zero. Example: 2

mm - month with leading zero

m - month without leading zero

dd - day with leading zero

d - day without leading zero

Date - strings

mmmm - Month name. Full form

mmm - Month name. Only first 3 symbols

dddd - Day of week. Full form

ddd - Day of week. Only first 3 symbols

Time

HH24 - 24 hours time with leading zero

HH - 24 hours time with leading zero. Shortcut

HH12 - 12 hours time with leading zero. Should be used together with ampm

H24 - 24 hours time without leading zero

H - 24 hours time without leading zero. Shortcut

H12 - 12 hours time without leading zero. Should be used together with ampm

MM - Minutes with leading zero

M - Minutes without leading zero

SS - Seconds with leading zero

S - Seconds without leading zero

LL - Milliseconds with leading zero

L - Milliseconds without leading zero

Special

ampm - Current half of the day as am or pm

AMPM - Current half of the day as AM or PM

UTC - Time zone offset. Example +1 or -2:30

Keywords

date

FAQs

Package last updated on 05 Feb 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts