pretty-ymd
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 = ; ymd// => "2018-01-01 05:05:02" const date = ;ymd// => "2018-01-10" const now = ;ymd// => "05:05:02" ymd;// => "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 = ;ymd// => "2018-07-14"
getCurrentDate
Same as getDate
but for the current date.
ymd// => "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 = ;ymd// => "2018-07-14 00:39"
getCurrentDatetime
Same as getDatetime
but for the current date.
ymd// => "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 = ;ymd// => "00:39"
getCurrentTime
Same as getTime
but for the current date.
ymd// => "00:39"
getYear
Returns the full year of the date argument passed.
const now = ;ymd// => "2018"
getCurrentYear
Returns the full year of the current date.
ymd// => "2018"
getMonth
Returns the month of the date argument passed. Will always return 2 characters, starting with 01
const now = ;ymd// => "07"
getCurrentMonth
Same as getMonth
but for the current date.
ymd// => "07"
getDay
Returns the day of the date argument passed. Will always return 2 characters, starting with 01
const now = ;ymd// => "14"
getCurrentDay
Same as getDay
but for the current date.
ymd// => "14"
getHours
Returns the hours for the date argument passed. Will always return 2 characters, starting with 01
const now = ;ymd// => "00"
getCurrentHours
Same as getHours
but for the current date.
ymd// => "00"
getMinutes
Returns the minutes for the date argument passed. Will always return 2 characters, starting with 01
const now = ;ymd// => "45"
getCurrentMinutes
Same as getMinutes
but for the current date.
ymd// => "45"
getSeconds
Returns the seconds for the date argument passed. Will always return 2 characters, starting with 01
const now = ;ymd// => "59"
getCurrentSeconds
Same as getSeconds
but for the current date.
ymd// => "59"
License
MIT © Pablo Rosales