mirror of
https://github.com/samsonjs/strftime.git
synced 2026-04-27 14:57:37 +00:00
update readme for 0.9 API
This commit is contained in:
parent
6ab81c89cb
commit
e16f49f4c0
1 changed files with 40 additions and 27 deletions
61
Readme.md
61
Readme.md
|
|
@ -12,6 +12,14 @@ Installation
|
||||||
npm install strftime
|
npm install strftime
|
||||||
|
|
||||||
|
|
||||||
|
The New API in 0.9
|
||||||
|
==================
|
||||||
|
|
||||||
|
The current version, 0.9, deprecates the older API that exported several functions: `strftimeTZ`, `strftimeUTC`, and `localizedStrftime`. In addition to this the exported function referenced itself as `require('strftime').strftime` for consistency with the other functions. *These functions are deprecated in 0.9 and will be removed in 1.0.*
|
||||||
|
|
||||||
|
Now you only need the single object exported and you can create a specialized version of it using the functions `utc()`, `localize(locale)`, and `timezone(offset)`. You can no longer pass in a timezone or locale on each call to `strftime` which is a regression. If you need this let me know and we will add it back into the API.
|
||||||
|
|
||||||
|
|
||||||
Usage
|
Usage
|
||||||
=====
|
=====
|
||||||
|
|
||||||
|
|
@ -26,38 +34,42 @@ If you want to localize it:
|
||||||
var it_IT = {
|
var it_IT = {
|
||||||
days: ['domenica', 'lunedi', 'martedi', 'mercoledi', 'giovedi', 'venerdi', 'sabato'],
|
days: ['domenica', 'lunedi', 'martedi', 'mercoledi', 'giovedi', 'venerdi', 'sabato'],
|
||||||
shortDays: ['dom', 'lun', 'mar', 'mer', 'gio', 'ven', 'sab'],
|
shortDays: ['dom', 'lun', 'mar', 'mer', 'gio', 'ven', 'sab'],
|
||||||
|
months: ['gennaio', 'febbraio', 'marzo', 'aprile', 'maggio', 'giugno', 'luglio', 'agosto', 'settembre', 'ottobre', 'novembre', 'dicembre'],
|
||||||
months: [ 'gennaio', 'febbraio', 'marzo', 'aprile', 'maggio', 'giugno', 'luglio',
|
shortMonths: ['gen', 'feb', 'mar', 'apr', 'mag', 'giu', 'lug', 'ago', 'set', 'ott', 'nov', 'dic'],
|
||||||
'agosto', 'settembre', 'ottobre', 'novembre', 'dicembre' ],
|
|
||||||
|
|
||||||
shortMonths: [ 'gen', 'feb', 'mar', 'apr', 'mag', 'giu', 'lug', 'ago',
|
|
||||||
'set', 'ott', 'nov', 'dic' ],
|
|
||||||
AM: 'AM',
|
AM: 'AM',
|
||||||
PM: 'PM'
|
PM: 'PM',
|
||||||
|
am: 'am',
|
||||||
|
pm: 'pm',
|
||||||
|
formats: {
|
||||||
|
D: '%m/%d/%y',
|
||||||
|
F: '%Y-%m-%d',
|
||||||
|
R: '%H:%M',
|
||||||
|
r: '%I:%M:%S %p',
|
||||||
|
T: '%H:%M:%S',
|
||||||
|
v: '%e-%b-%Y'
|
||||||
}
|
}
|
||||||
console.log(strftime('%B %d, %Y %H:%M:%S', it_IT)) // => aprile 28, 2011 18:21:08
|
}
|
||||||
console.log(strftime('%B %d, %Y %H:%M:%S', new Date(1307472705067), it_IT)) // => giugno 7, 2011 18:51:45
|
var strftimeIT = strftime.localize(it_IT)
|
||||||
|
console.log(strftimeIT('%B %d, %Y %H:%M:%S')) // => aprile 28, 2011 18:21:08
|
||||||
And if you don't want to pass a localization object every time you can get a localized `strftime` function like so:
|
console.log(strftimeIT('%B %d, %Y %H:%M:%S', new Date(1307472705067))) // => giugno 7, 2011 18:51:45
|
||||||
|
|
||||||
var strftime = require('strftime')
|
|
||||||
var it_IT = { /* same as above */ }
|
|
||||||
var strftime_IT = strftime.localizedStrftime(it_IT)
|
|
||||||
console.log(strftime_IT('%B %d, %Y %H:%M:%S')) // aprile 28, 2011 18:21:08
|
|
||||||
|
|
||||||
|
|
||||||
Time zones can be passed in as an offset from GMT in minutes.
|
Time zones can be passed in as an offset from GMT in minutes.
|
||||||
|
|
||||||
var strftimeTZ = require('strftime').strftimeTZ
|
var strftime = require('strftime')
|
||||||
console.log(strftimeTZ('%B %d, %y %H:%M:%S', new Date(1307472705067), -420)) // => June 07, 11 11:51:45
|
var strftimePDT = strftime.timezone(-420)
|
||||||
console.log(strftimeTZ('%F %T', new Date(1307472705067), 120)) // => 2011-06-07 20:51:45
|
var strftimeCEST = strftime.timezone(120)
|
||||||
|
console.log(strftimePDT('%B %d, %y %H:%M:%S', new Date(1307472705067))) // => June 07, 11 11:51:45
|
||||||
|
console.log(strftimeCEST('%F %T', new Date(1307472705067))) // => 2011-06-07 20:51:45
|
||||||
|
|
||||||
|
|
||||||
Alternatively you can use the timezone format used by ISO 8601, `+HHMM` or `-HHMM`.
|
Alternatively you can use the timezone format used by ISO 8601, `+HHMM` or `-HHMM`.
|
||||||
|
|
||||||
var strftimeTZ = require('strftime').strftimeTZ
|
var strftime = require('strftime')
|
||||||
console.log(strftimeTZ('', new Date(1307472705067), '-0700')) // => June 07, 11 11:51:45
|
var strftimePDT = strftime.timezone('-0700')
|
||||||
console.log(strftimeTZ('%F %T', new Date(1307472705067), '+0200')) // => 2011-06-07 20:51:45
|
var strftimeCEST = strftime.timezone('+0200')
|
||||||
|
console.log(strftimePDT('', new Date(1307472705067))) // => June 07, 11 11:51:45
|
||||||
|
console.log(strftimeCEST('%F %T', new Date(1307472705067))) // => 2011-06-07 20:51:45
|
||||||
|
|
||||||
|
|
||||||
Supported Specifiers
|
Supported Specifiers
|
||||||
|
|
@ -120,16 +132,17 @@ solves some awkwardness with formats like `%l`.
|
||||||
Contributors
|
Contributors
|
||||||
============
|
============
|
||||||
|
|
||||||
|
* [Rob Colburn](https://github.com/robcolburn)
|
||||||
|
* [Alexandr Nikitin](https://github.com/alexandrnikitin)
|
||||||
* [Sami Samhuri](https://github.com/samsonjs)
|
* [Sami Samhuri](https://github.com/samsonjs)
|
||||||
* [Andrew Schaaf](https://github.com/andrewschaaf)
|
* [Andrew Schaaf](https://github.com/andrewschaaf)
|
||||||
* [Rob Colburn](https://github.com/robcolburn)
|
|
||||||
* [Ryan Stafford](https://github.com/ryanstafford)
|
* [Ryan Stafford](https://github.com/ryanstafford)
|
||||||
|
|
||||||
|
|
||||||
License
|
License
|
||||||
=======
|
=======
|
||||||
|
|
||||||
Copyright 2010 - 2013 Sami Samhuri sami@samhuri.net
|
Copyright 2010 - 2015 Sami Samhuri sami@samhuri.net
|
||||||
|
|
||||||
[MIT license](http://sjs.mit-license.org)
|
[MIT license](http://sjs.mit-license.org)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue