Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
strftime for JavaScript, works in Node.js and browsers, supports localization. Most standard specifiers from C are supported as well as some other extensions from Ruby.
npm install strftime
var strftime = require('strftime')
console.log(strftime('%B %d, %y %H:%M:%S')) // => April 28, 2011 18:21:08
console.log(strftime('%F %T', new Date(1307472705067))) // => 2011-06-07 18:51:45
If you want to localize it:
var strftime = require('strftime')
var it_IT = {
days: [ 'domenica', 'lunedi', 'martedi', 'mercoledi', 'giovedi', 'venerdi', 'sabato' ],
shortDays: [ 'dom', 'lun', 'mar', 'mer', 'gio', 'ven', 'sab' ],
months: [ 'gennaio', 'febbraio', 'marzo', 'aprile', 'maggio', 'giugno', 'luglio',
'agosto', 'settembre', 'ottobre', 'novembre', 'dicembre' ],
shortMonths: [ 'gen', 'feb', 'mar', 'apr', 'mag', 'giu', 'lug', 'ago',
'set', 'ott', 'nov', 'dic' ],
AM: 'AM',
PM: 'PM'
}
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
And if you don't want to pass a localization object every time you can get a localized strftime
function like so:
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
Extensions from Ruby are noted in the following list.
Unsupported specifiers are rendered without the percent sign.
e.g. %q
becomes q
. Use %%
to get a literal %
sign.
%m/%d/%y
%Y-%m-%d
%H:%M
%I:%M:%S %p
%H:%M:%S
%e-%b-%Y
For more detail see man 3 strftime
as the format specifiers should behave
identically. If behaviour differs please file a bug.
Any specifier can be modified with -
, _
, or 0
as well, as in Ruby.
Using %-
will omit any leading zeroes or spaces, %_
will force spaces
for padding instead of the default, and %0
will force zeroes for padding.
There's some redundancy here as %-d
and %e
have the same result, but it
solves some awkwardness with formats like %l
.
Copyright 2010 - 2013 Sami Samhuri sami@samhuri.net
FAQs
strftime for JavaScript
We found that strftime demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.