dateformat
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|
The dateformat library is a useful Node.js package inspired by the excellent dateFormat() function by Steven Levithan. The package comes in handy when needing to handle date formatting in JavaScript. With this, you can neatly manipulate date strings to different formats depending on your requirements.
The usage of the dateformat package is straightforward, initiated by installing the package via npm using the command npm install dateformat
. After that, you can import it into your JavaScript code and use it as per your necessitations.
Below are a few usage examples:
import dateFormat, { masks } from "dateformat";
const now = new Date();
// Basic usage
dateFormat(now, "dddd, mmmm dS, yyyy, h:MM:ss TT");
//Result: Saturday, June 9th, 2007, 5:46:21 PM
// Using named masks
dateFormat(now, "isoDateTime");
// Result: 2007-06-09T17:46:21
// Adding your own custom mask
masks.hammerTime = 'HH:MM! "Can\'t touch this!"';
dateFormat(now, "hammerTime");
// Result: 17:46! Can't touch this!
// Providing the date as a string
dateFormat("Jun 9 2007", "fullDate");
// Result: Saturday, June 9, 2007
Realize that the function accepts three parameters and if you don't include the date argument, the current date and time is used. If you don't include the mask argument, then dateFormat.masks.default
is used instead.
The detailed documentation for dateformat can be located on the package's Github page here. The readme provides comprehensive information on how to use the library, including modifications, usage examples, mask options, named formats, and localization details. Therefore, it's your go-to resource when seeking to understand the package's workings fully.