2.2.0 • Published 6 years ago

time-stamp v2.2.0

Weekly downloads
3,170,708
License
MIT
Repository
github
Last release
6 years ago

time-stamp NPM version NPM monthly downloads NPM total downloads Linux Build Status

Get a formatted timestamp.

Please consider following this project's author, Jon Schlinkert, and consider starring the project to show your :heart: and support.

(TOC generated by verb using markdown-toc)

Install

Install with npm:

$ npm install --save time-stamp

Usage

const timestamp = require('time-stamp');

console.log(timestamp());
//=> 2018-10-26

console.log(timestamp.utc());
//=> 2018-10-26

Customizing the timestamp

You may also pass a string to format the generated timestamp.

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

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

Release history

v2.0.0

Breaking changes

Default pattern was changed from YYYY:MM:DD to YYYY-MM-DD. See issues/3 for more details.

About

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.

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:

$ npm install && npm test

(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:

$ npm install -g verbose/verb#dev verb-generate-readme && verb

Related projects

You might also be interested in these projects:

Contributors

CommitsContributor
31jonschlinkert
7doowb
1evocateur
1mendenhallmagic
1mvanroon
1leesei
1sleagon

Author

Jon Schlinkert

License

Copyright © 2018, Jon Schlinkert. Released under the MIT License.


This file was generated by verb-generate-readme, v0.8.0, on October 26, 2018.

rainbow-logalgotia-test-packageopex-backend-console-loggeropex-loggerreact-native-bluetooth2killi8n-react-native-fast-imagern-send-smsgew-nodejs-api-client@arisageha/react-lazyload@arisageha/react-lazyload-fixtest2-ericautotrading_bitskinszemez-buildreact-native-template-rfbaseairscanairscan-examplereact-native-esc-pos-sahaab@borisovart/atol-kkt-moduledeneme323112@ntt_app/react-native-custom-notificationreact-native-covid-sdkknight-item-1ember-i18n-exportreact-native-thanh-toast-library@thanhnguyen14797/react-native-thanh-toast-librarycthpb-plugin-socialrf-profile-managertwilight-toolkitsharletpconsole.jspanqibaoreact-native-printer-brothersrn-pdf-reader-offline@infinitebrahmanuniverse/nolb-time-@opendesign/octopus-ai@everything-registry/sub-chunk-2945pack_wprkoxyz-buildpaladins-clientnot-fancy-lognpm_qwertynodejs_11npm_one_12_34_1_npm_one_1_2_3npm_one_2_2payutestingpcfepcfe-clipeter.you.jqweui.test.publishobject-file-syncppackpresonarpackage_lsq_zxcvnode-elmnative-google-loginnative-kakao-login@deskpro/apps-dpat@cdevine49/react-numeric-input@dexon-foundation/remix-simulator@cbrgpl/ttt-source-parser@cbrgpl/ttt-testbirken-react-native-community-image-editor@chkp/harmony-endpoint-management-sdkbitwig-nks-preview-generator@docgeni/toolkit@corelmax/react-native-my2c2p-sdk@considonet/g-loggerbuildteam-common@cloudstitch/clibojhelperbridgeline-kabinetbxs-ui-vue@ctfdio/picocss-themescallista@dan/cryptocoins-iconschainsql-remix-simulatorchalklogchapters02changelog-helperwc-starterkitzeo-loggerzyl@bfrydl/archer-service@bradtech/lora2db@buganto/client@geeky-apo/react-native-advanced-clipboardvideo-multi-uploader@hemith/react-native-tnkcomposer-errorscornerstone-kitcli-utils@mapbox/underreactfofx@mapbox/batfish@mapbox/sticklerfirebase-chat-managerfishzero3.0.0@brucearmstrong/sass-librarylayui-custom@designble/log-utils
2.2.0

6 years ago

2.1.0

6 years ago

2.0.1

6 years ago

2.0.0

7 years ago

1.1.0

7 years ago

1.0.1

8 years ago

1.0.0

8 years ago

0.1.3

8 years ago

0.1.2

8 years ago

0.1.1

9 years ago

0.1.0

9 years ago