Get a formatted timestamp.
npm install time-stamp> Get a formatted timestamp.
Please consider following this project's author, Jon Schlinkert, and consider starring the project to show your :heart: and support.
- Install
- Usage
- Customizing the timestamp
- Release history
* v2.0.0
- About
_(TOC generated by verb using markdown-toc)_
Install with npm:
``sh`
$ npm install --save time-stamp
`js
const timestamp = require('time-stamp');
console.log(timestamp());
//=> 2018-10-26
console.log(timestamp.utc());
//=> 2018-10-26
`
You may also pass a string to format the generated timestamp.
`js
console.log(timestamp('YYYYMMDD'));
//=> 20181026
console.log(timestamp.utc('YYYYMMDD'));
//=> 20181026
`
Supported patterns
* YYYY: full year (ex: 2018)MM
* : month (ex: 04)DD
* : day (ex: 01)HH
* : hours (ex: 12)mm
* : minutes (ex: 59)ss
* : seconds (ex: 09)ms
* : milliseconds (ex: 532)
Usage Examples
`js
console.log(timestamp('YYYYMMDD'));
//=> 20181026
console.log(timestamp.utc('YYYYMMDD'));
//=> 20181026
console.log(timestamp('YYYYMMDD:ss'));
//=> 20181026:24
console.log(timestamp.utc('YYYYMMDD:ss'));
//=> 20181026:24
console.log(timestamp('YYYY/MM/DD:mm:ss'));
//=> 2018/10/26:46:24
console.log(timestamp.utc('YYYY/MM/DD:mm:ss'));
//=> 2018/10/26:46:24
console.log(timestamp('YYYY:MM:DD'));
//=> 2018:10:26
console.log(timestamp.utc('YYYY:MM:DD'));
//=> 2018:10:26
console.log(timestamp('[YYYY:MM:DD]'));
//=> [2018:10:26]
console.log(timestamp.utc('[YYYY:MM:DD]'));
//=> [2018:10:26]
console.log(timestamp('YYYY/MM/DD'));
//=> 2018/10/26
console.log(timestamp.utc('YYYY/MM/DD'));
//=> 2018/10/26
console.log(timestamp('YYYY:MM'));
//=> 2018:10
console.log(timestamp.utc('YYYY:MM'));
//=> 2018:10
console.log(timestamp('YYYY'));
//=> 2018
console.log(timestamp.utc('YYYY'));
//=> 2018
console.log(timestamp('MM'));
//=> 10
console.log(timestamp.utc('MM'));
//=> 10
console.log(timestamp('DD'));
//=> 26
console.log(timestamp.utc('DD'));
//=> 26
console.log(timestamp('HH'));
//=> 00
console.log(timestamp.utc('HH'));
//=> 04
console.log(timestamp('mm'));
//=> 46
console.log(timestamp.utc('mm'));
//=> 46
console.log(timestamp('ss'));
//=> 24
console.log(timestamp.utc('ss'));
//=> 24
console.log(timestamp('ms'));
//=> 186
console.log(timestamp.utc('ms'));
//=> 186
`
Breaking changes
Default pattern was changed from YYYY:MM:DD to YYYY-MM-DD. See issues/3 for more details.
Contributing
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Running Tests
Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:
`sh`
$ npm install && npm test
Building docs
_(This project's readme.md is generated by verb, please don't edit the readme directly. Any changes to the readme must be made in the .verb.md readme template.)_
To generate the readme, run the following command:
`sh``
$ npm install -g verbose/verb#dev verb-generate-readme && verb
You might also be interested in these projects:
* days: Days of the week. | homepage
* iso-week: Get the ISO week of the year. | homepage
* month: Get the name or number of the current month or any month of the year. | homepage
* months: Months of the year. | homepage
* o-clock: Simple javascript utility for displaying the time in 12-hour clock format. | homepage
* seconds: Get the number of seconds for a minute, hour, day and week. | homepage
* week: Get the current week number. | homepage
* weekday: Get the name and number of the current weekday. Or get the name of the… more | homepage
* year: Simple utility to get the current year with 2 or 4 digits. | homepage
| Commits | Contributor |
| --- | --- |
| 31 | jonschlinkert |
| 7 | doowb |
| 1 | evocateur |
| 1 | mendenhallmagic |
| 1 | mvanroon |
| 1 | leesei |
| 1 | sleagon |
Jon Schlinkert
* GitHub Profile
* Twitter Profile
* LinkedIn Profile
Copyright © 2018, Jon Schlinkert.
Released under the MIT License.
*
_This file was generated by verb-generate-readme, v0.8.0, on October 26, 2018._