New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

@rangerrick/moment-javaformat

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@rangerrick/moment-javaformat

Format Moment.js using Java format strings

latest
Source
npmnpm
Version
2.0.12
Version published
Weekly downloads
552
-15.08%
Maintainers
1
Weekly downloads
 
Created
Source

moment-javaformat

CircleCI

This plugin for Moment.js adds support for formatting using the Java SimpleDateFormat and DateTimeFormatter format options.

It differs from moment-jdateformatparser in that it doesn't just try to translate Java format strings to Moment, but instead implements a new set of format methods that can handle a wider range of Java format strings, at the expense of speed.

Thanks to moment-jdateformatparser for the basic idea, I ran with it in my own way because we needed some formats that just plain aren't possible in a simple format string translation. :)

Version History

Changes made in the develop branch are checked against unit tests upon commit. The latest CHANGELOG.md is then auto-generated from the commit history and merged to main.

Requirements

This plugin requires loading either moment or moment-timezone, but some functionality will be undefined or fail if you are using Moment.js without timezone support.

Usage

In most cases, all you should have to do is load this module after you load moment, and then new methods are available to you for formatting:

const moment = require("moment-timezone");
require("@rangerrick/moment-javaformat");

let now = moment("2020-01-01T15:00:00Z");
// a format matching Java 8 SimpleDateFormat definitions
now.formatJavaSDF("yyyy-MM-dd HH:mm"); // 2020-01-01 15:00

// a format matching Java 8 DateTimeFormatter definitions
now.formatJavaDTF("yyyy-MM-dd HH:mm:ss O"); // 2020-01-01 15:00:00 GMT-05:00

Installation

You can install moment-javaformat from npm in the usual ways:

# install using npm
npm install --save @rangerrick/moment-javaformat

# install using yarn
yarn add @rangerrick/moment-javaformat

Caveats

A few format strings are difficult to implement without going deeper down the rabbit hole than I was willing to go. ;)

  • SimpleDateFormat: W (week-of-month), F (day-of-week-in-month)
  • DateTimeFormatter: W (week-of-month), F (day-of-week-in-month), n (nano-of-second), N (nano-of-day)

I might implement the nano ones if I get around to doing the math (and probing window.performance.now()) but Date objects don't have that level of accuracy anyway.

License

moment-javaformat is freely distributable under the terms of the MIT license.

Copyright (c) 2020-2024 Benjamin Reed.

Keywords

moment

FAQs

Package last updated on 20 Aug 2025

Did you know?

Socket

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.

Install

Related posts