npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

date-format-utils

v2.2.0

Published

Formatting of date object,valid date string, timestamp into string and converting date object into timestamp

Downloads

341

Readme

Installation :

$ npm install date-format-utils

Usages :

var dateUtil = require('date-format-utils');

// formatDate(Date,FormatStyle,Timezone);
// Date => 'Timestamp ,date object or valid date string'
// FormatStyle => 'Format string, e.g. `yyyy-MM-dd HH:mm:ss.SSS`'
// Timezone => 'Timezone of date [Optional]'

dateUtil.formatDate(new Date()); // Default to format 'yyyy-MM-dd hh:mm:ss.SSS tt'
dateUtil.formatDate(new Date(),'yyyy-MM-dd'); // Show date
dateUtil.formatDate(new Date(),'hh:mm:ss tt',480); // Show time [Specify Timezone]

// You can convert a date into timestamp using toTimestamp(Date,Option)
// Date => 'date object or valid date string'
// Option => 'timestamp option [timestamp in sec,timestamp in millisecond]
// Default option is millisecond

dateUtil.toTimestamp(new Date()); //Show timestamp in milliseconds [Default]
dateUtil.toTimestamp(new Date(),'ms'); //Show timestamp in milliseconds
dateUtil.toTimestamp(new Date(),'sec'); //Show timestamp in sec

The following describes the custom date and time format specifiers :

  • "dd" : The day of the month, from 01 through 31.
  • "ddd" : The abbreviated name of the day of the week.
  • "dddd" : The full name of the day of the week.
  • "MM" : The month, from 01 through 12.
  • "MMM" : The abbreviated name of the month.
  • "MMMM" : The full name of the month.
  • "yy" : The year, from 00 to 99.
  • "yyyy" : The year as a four-digit number.
  • "hh" : The hour, using a 12-hour clock from 01 to 12.
  • "HH" : The hour, using a 24-hour clock from 00 to 23.
  • "mm" : The minute, from 00 through 59.
  • "ss" : The second, from 00 through 59.
  • "SSS" : The milliseconds in a date and time value.
  • "tt" : The AM/PM designator.
  • "K" : Time zone information.

Basic Example :

var dateUtil = require('date-format-utils');
var date = new Date('1/18/2017, 1:30:00 PM');
console.log(dateUtil.formatDate(date,dateUtil.ISO8601_FORMAT,330));
console.log(dateUtil.formatDate(date,dateUtil.ISO8601_WITH_TZ_OFFSET_FORMAT,330));
console.log(dateUtil.formatDate(date,dateUtil.DATETIME_FORMAT,330));
console.log(dateUtil.formatDate(date,dateUtil.DATE_FORMAT,330));
console.log(dateUtil.formatDate(date,dateUtil.TIME_FORMAT,330));

console.log(dateUtil.toTimestamp(date));
console.log(dateUtil.toTimestamp(date,'ms'));
console.log(dateUtil.toTimestamp(date,'sec'));
console.log(dateUtil.toTimestamp(date,'xyz'));

// The example displays the following output:
//      2017-01-18 13:30:00.000
//      2017-01-18T13:30:00.000 +0530
//      2017-01-18 01:30:00.000 PM
//      2017-01-18
//      01:30:00 PM

//      1484726400000
//      1484726400000
//      1484726400
//      Invalid Timestamp Option