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