Giter Club home page Giter Club logo

pretty-ymd's Introduction

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

pretty-ymd's People

Contributors

neuralch avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.