Latest Threat ResearchGlassWorm Loader Hits Open VSX via Developer Account Compromise.Details
Socket
Book a DemoInstallSign in
Socket

ymd

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

ymd

JavaScript component to return the year, month, and day string. i.e. returns `YYYY-MM-dd` from Date object.

Source
npmnpm
Version
0.1.0
Version published
Maintainers
1
Created
Source

ymd

JavaScript component to return the year, month, and day string. i.e. returns YYYY-MM-dd from Date object.

Why?

It's a one liner that I got tired of writing over and over again.

Here it is:

function ymd (date) {
  return date.getFullYear() + '-' + ('0' + (1 + date.getMonth())).slice(-2) + '-' + ('0' + date.getDate()).slice(-2)
}

Node.js/Browserify

npm install --save ymd

Component

component install jprichardson/ymd

Methods

ymd

  • returns using local timezone

ymd.utc

  • returns using UTC timezone

Example

var ymd = require('ymd')

ymd.utc(new Date('2013-03-05')) //2013-03-05

// input to Date() is still being parsed as UTC, may be different for your timezone
ymd(new Date('2013-03-05 4:43 PM')) //2013-03-05

License

(MIT License)

Copyright 2013, JP Richardson jprichardson@gmail.com

Keywords

date

FAQs

Package last updated on 23 Jul 2014

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