Skip to content
This repository has been archived by the owner on Dec 30, 2021. It is now read-only.
/ pretty-ymd Public archive

Get YMD HMS format strings from your Date objects or the current Date

License

Notifications You must be signed in to change notification settings

NeurAlch/pretty-ymd

Repository files navigation

pretty-ymd Build Status: Linux and macOS

Get YMD HMS format strings from your Date objects or the current Date

Simple collection of functions for getting the common YMD HMS format for dates and datetime, used in things like databases and logging.

Install

$ npm install pretty-ymd

Usage

const ymd = require("pretty-ymd");

ymd.getCurrentDatetime()
// => "2018-01-01 05:05:02"

const date = new Date();
ymd.getDate(date)
// => "2018-01-10"

const now = new Date();
ymd.getTime(now)
// => "05:05:02"

ymd.getCurrentMinutes();
// => "05"

Methods

getDate

Returns a string with the format yyyy-mm-dd for the date argument passed.

Month and Day will always have two characters starting with 01

const date = new Date();
ymd.getDate(date)
// => "2018-07-14"

getCurrentDate

Same as getDate but for the current date.

ymd.getCurrentDate()
// => "2018-07-14"

getDatetime

Returns a string with the format yyyy-mm-dd HH:MM:ss for the date argument passed.

Month, Day, Hour, Minute and Second will always have two characters starting with 01

const date = new Date();
ymd.getDatetime(date)
// => "2018-07-14 00:39"

getCurrentDatetime

Same as getDatetime but for the current date.

ymd.getCurrentDatetime()
// => "2018-07-14 00:39"

getTime

Returns a string with the format HH:MM:ss for the date argument passed.

Hours, Minutes and seconds will always have two characters starting with 01

const date = new Date();
ymd.getTime(date)
// => "00:39"

getCurrentTime

Same as getTime but for the current date.

ymd.getCurrentTime()
// => "00:39"

getYear

Returns the full year of the date argument passed.

const now = new Date();
ymd.getYear(now)
// => "2018"

getCurrentYear

Returns the full year of the current date.

ymd.getCurrentYear()
// => "2018"

getMonth

Returns the month of the date argument passed.

Will always return 2 characters, starting with 01

const now = new Date();
ymd.getMonth(now)
// => "07"

getCurrentMonth

Same as getMonth but for the current date.

ymd.getCurrentMonth()
// => "07"

getDay

Returns the day of the date argument passed.

Will always return 2 characters, starting with 01

const now = new Date();
ymd.getDay(now)
// => "14"

getCurrentDay

Same as getDay but for the current date.

ymd.getCurrentDay()
// => "14"

getHours

Returns the hours for the date argument passed.

Will always return 2 characters, starting with 01

const now = new Date();
ymd.getHours(now)
// => "00"

getCurrentHours

Same as getHours but for the current date.

ymd.getCurrentHours()
// => "00"

getMinutes

Returns the minutes for the date argument passed.

Will always return 2 characters, starting with 01

const now = new Date();
ymd.getMinutes(now)
// => "45"

getCurrentMinutes

Same as getMinutes but for the current date.

ymd.getCurrentMinutes()
// => "45"

getSeconds

Returns the seconds for the date argument passed.

Will always return 2 characters, starting with 01

const now = new Date();
ymd.getSeconds(now)
// => "59"

getCurrentSeconds

Same as getSeconds but for the current date.

ymd.getCurrentSeconds()
// => "59"

License

MIT © Pablo Rosales

About

Get YMD HMS format strings from your Date objects or the current Date

Resources

License

Stars

Watchers

Forks

Packages

No packages published