Easy library for date formatting.
Алексей 301354e9d1 1.0.1 1 month ago
LICENSE.md add license 3 months ago
README.md bump to npm 1 month ago
example.html change patterns and add new 3 months ago
jsdateformatter.js fix incorrect hours bug and improved readme 3 months ago
jsdateformatter.min.js fix incorrect hours bug and improved readme 3 months ago
package.json 1.0.1 1 month ago
screenshot.png fix incorrect hours bug and improved readme 3 months ago

README.md

JSDateFormatter

Easy library for date formatting.

Install: npm i jsdateformatter

API

  • JSDateFormatter.parse(format, date, utc) - get string date formatted
  • JSDateFormatter.getMap(format, date, utc) - get parsed date, return object {YYYY: 2018, …}

Arguments

  • format - string, see below
  • date - Date object or null
  • utc - boolean, use UTC time if true

Format

YYYY-MM-DD d hh:mm:ss.SSS, A, B

  • Y - year
  • M - month
  • D - month day
  • d - week day
  • h - 24-h hours
  • H - AM/PM 12-h hours
  • m - minutes
  • s - seconds
  • S - milliseconds
  • A - full localized month day
  • a - short (first 3 symbols) localized month day
  • B - full localized week day
  • b - short (first 3 symbols) localized week day
  • p - AM/PM

Y - cutting on the left

S - cutting on the right

M, D, h, m, s - no add first zero

MM, DD, hh, mm, ss - only two numbers, add first zero if 0-9

Examples

  • hh:mm -> 00:01
  • YYYY-MM-DD d hh:mm:ss.SSS -> 2018-06-26 4 00:01:24.299
  • YY-M-D d h:m:s.SS -> 18-6-26 4 0:1:24.29
  • a, DD b, H:mm p -> чет, 26 июл, 6:37 PM