4.0.1 • Published 2 years ago

php-date v4.0.1

Weekly downloads
20
License
MIT
Repository
github
Last release
2 years ago

php-date

Tests Version on npm

This package aims to mimic the formatting of PHP's date function in JavaScript.

  • Almost all tokens are supported
  • Tiny (1.2KB minified & gzipped)
  • Type annotations included
  • Works in all modern browsers, IE11 and Node.js

Installation

Install via npm:

npm install --save php-date

Or use in the browser via unpkg (using the global phpDate variable):

<script src="https://unpkg.com/php-date"></script>

Usage

The signature looks like this:

date (formatter: string, date: Date = new Date): string

So just use it mostly like in PHP:

const date = require('php-date')

const releaseDate = new Date(2016, 9, 18)

date('d.m.Y', releaseDate) // 18.10.2016
date('F jS Y', releaseDate) // October 18th 2016

Sometimes you want to format a given date for the UTC timezone. You can do so by using the date.UTC function, it has the same signature as the date function itself:

date.UTC(...)

The second argument is completely optional; like in PHP this will default to the current point in time.

Timezone Identifiers

The only PHP date tokens not supported by this package are timezones (tokens e and T) which would return timezone identifiers. I felt like that would bloat the code a little too much with the fallbacks necessary for older browsers.

4.0.1

2 years ago

4.0.0

2 years ago

3.0.1

3 years ago

3.0.0

5 years ago

2.2.2

5 years ago

2.2.1

5 years ago

2.2.0

5 years ago

2.1.2

5 years ago

2.1.1

6 years ago

2.1.0

7 years ago

2.0.0

7 years ago

1.1.0

7 years ago

1.0.1

7 years ago

1.0.0

8 years ago