Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
intl-dateformat
Advanced tools
Features • Installation • Example • Usage
intl-dateformat is a simple date formatting library that leverage the Intl.DateTimeFormat API to format dates in different languages and timezones without having to clutter your JavaScript bundles.
Intl.DateTimeFormat
, there is no need to bundle additional locales or a timezones database. It's already in your Browser!$ npm install intl-dateformat
import formatDate from 'intl-dateformat'
const date = new Date(Date.UTC(1984, 0, 17, 16, 13, 37, 0))
formatDate(date, 'YYYY-MM-DD hh:mm:ss A')
// → 1984-01-17 04:13:37 PM
formatDate(date, 'YYYY, MMMM dddd DD')
// → 1984, January Tuesday 17
formatDate(date, 'YYYY-MM-DD hh:mm:ss A', { timezone: 'Asia/Singapore' })
// → 1984-01-18 00:13:37 AM
formatDate(date, 'YYYY, MMMM dddd DD', { locale: 'fr' })
// → 1984, Janvier Mercredi 18
import formatDate from 'intl-dateformat'
const date = new Date(Date.UTC(1984, 0, 17, 16, 13, 37, 0))
formatDate(date, 'YYYY-MM-DD hh:mm:ss A')
// → 1984-01-17 04:13:37 PM
Argument | Description | Type |
---|---|---|
date | The date to format | Date , number |
format | The mask used to format | See Formats |
options | Custom locale or timezone | See Options |
Mask | Description | Example |
---|---|---|
YYYY | 4-digits year | 1984 |
YY | 2-digits year | 84 |
MMMM | Month name | January |
MMM | Short month name | Jan |
DD | 2-digits day | 17 |
dddd | Day of the week | Tuesday |
ddd | Short day of the week | Tue |
A | Day period | AM , PM |
a | Lowercased day period | am , pm |
HH | 24-hours hour | 16 |
hh | 12-hours hour | 04 |
mm | 2-digit minute | 13 |
ss | 2-digit second | 37 |
locale
- A BCP 47 tag to identify the output language
string
fr
, fr-FR
timezone
- A IANA timezone
string
Europe/Paris
, America/Chicago
If you find yourself missing some date parts, no problem we got you covered. You can create your own dateFormat
function and add your custom formatters:
import { createDateFormatter } from 'intl-dateformat'
const formatDate = createDateFormatter({
// numeric hour
h: ({ hour }) => hour[0] === '0' ? hour[1] : hour
// milliseconds
SSS: (parts, date) => String(date.getTime()).slice(-3)
})
const date = new Date(Date.UTC(1984, 0, 17, 16, 13, 37, 0))
formatDate(date, 'YYYY-MM-DD h:mm:ss.SSS')
// → 1984-01-17 4:13:37.505
Argument | Description | Type |
---|---|---|
formatters | Custom formatters | See Formatters |
Formatters are represented as a dictionary of functions, where the key represents the mask that is to be matched in the format
and the value is the function that will format the date.
The formatter function takes the following arguments:
parts
- An object containing all the date parts provided by Intl.DateTimeFormat
. You can inspect the DatePartName type for an exhaustive list of all the date partsdate
- The original date passed to the formatDate
function.FAQs
Format a date using Intl.DateTimeFormat goodness.
We found that intl-dateformat demonstrated a not healthy version release cadence and project activity because the last version was released 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’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.