PHPackages                             wikimedia/timestamp - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. wikimedia/timestamp

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

wikimedia/timestamp
===================

Creation, parsing, and conversion of timestamps

v5.1.0(5mo ago)6701.2k↑17.4%33GPL-2.0-or-laterPHPPHP &gt;=8.1

Since Sep 30Pushed 2mo ago11 watchersCompare

[ Source](https://github.com/wikimedia/mediawiki-libs-Timestamp)[ Packagist](https://packagist.org/packages/wikimedia/timestamp)[ Docs](https://www.mediawiki.org/wiki/Timestamp)[ RSS](/packages/wikimedia-timestamp/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (9)Versions (13)Used By (3)

[![Latest Stable Version](https://camo.githubusercontent.com/593b3def9dff29a411f79b76977e0d659e1eced01d0396654d20b65e612eacf1/68747470733a2f2f706f7365722e707567782e6f72672f77696b696d656469612f74696d657374616d702f762f737461626c652e737667)](https://packagist.org/packages/wikimedia/timestamp) [![License](https://camo.githubusercontent.com/a565ba4b04b37b74c2fb325ec3161bf4dd9a194b3864aeb1638d869318a6536d/68747470733a2f2f706f7365722e707567782e6f72672f77696b696d656469612f74696d657374616d702f6c6963656e73652e737667)](https://packagist.org/packages/wikimedia/timestamp)

Convertible Timestamp for PHP
=============================

[](#convertible-timestamp-for-php)

This library provides a convenient wrapper around DateTime to create, parse, and format timestamps.

Additional documentation about the library can be found on [MediaWiki.org](https://www.mediawiki.org/wiki/Timestamp).

Supported formats
-----------------

[](#supported-formats)

On input, the following formats are recognized:

- A subset of [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) basic and extended formats:
    - Years before 0000 or after 9999 are not supported.
    - Week and ordinal dates are not supported.
    - Accuracy to seconds is required. Fractions of a second are supported to microsecond resolution.
    - If the timezone is omitted, UTC is assumed.
    - As an extension, the 'T' may be replaced with a single space.
- As a signed integer (up to 13 digits) representing seconds since the Unix epoch.
    - Optionally with decimal seconds to microsecond resolution, using '.' as the decimal separator.
- [RFC 2822](https://www.rfc-editor.org/rfc/rfc2822.html#section-3.3) format, including obsolete syntax.
    - CFWS tokens are not fully supported, use only FWS.
    - Note, per the RFC, all military timezones are considered as -0000.
    - As an extension, the timezone may be omitted entirely in which case UTC is assumed.
    - As an extension, anything after the first semicolon in the string is ignored.
- [RFC 850](https://www.rfc-editor.org/rfc/rfc850.html#section-2.1.4) format.
- [asctime](https://pubs.opengroup.org/onlinepubs/9699919799/functions/asctime.html) format.
- The `MW`, `DB`, `POSTGRES`, `ORACLE`, and `EXIF` formats described below.

For output, the following conversions are predefined in TimestampFormat:

- `DB`: MySQL datetime format: "2012-07-31 19:01:08"
- `EXIF`: Exif 2.2 format: "2012:07:31 19:01:08"
- `ISO_8601`: [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) expanded format: "2012-07-31T19:01:08Z"
- `ISO_8601_BASIC`: [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) basic format: "20120731T190108Z"
- `MW`: A 14-digit string: "20120731190108"
- `ORACLE`: A default Oracle timestamp format: "31-07-2012 19:01:08.000000"
- `POSTGRES`: PostgreSQL default timestamptz format: "2012-07-31 19:01:08+00"
- `RFC2822`: [RFC 2822](https://www.rfc-editor.org/rfc/rfc2822.html#section-3.3) format using an obsolete timezone: "Tue, 31 Jul 2012 19:01:08 GMT"
- `UNIX`: Seconds since the Unix epoch (1970-01-01T00:00:00Z): "1343761268".
- `UNIX_MICRO`: Seconds since the Unix epoch with microseconds: "1343761268.000000".

For backward compatibility with wikimedia/timestamp v5.0 and earlier, there are also global constants defined for these formats. The constants have names beginning with `TS_`, for example `TS_UNIX`. Use of these constants is discouraged in new code.

Usage
-----

[](#usage)

```
$ts = new ConvertibleTimestamp( '2012-07-31T19:01:08Z' );
$formatted = $ts->getTimestamp( TimestampFormat::UNIX );

// Shorthand
$formatted = ConvertibleTimestamp::convert(
    TimestampFormat::UNIX, '2012-07-31T19:01:08Z'
);

// Format using PHP date formatting codes
$formatted = $ts->format( 'Y-m-d H:i:s O' );
```

Running tests
-------------

[](#running-tests)

```
composer install --prefer-dist
composer test

```

Releasing a new version
-----------------------

[](#releasing-a-new-version)

This package uses `wikimedia/update-history` and its conventions.

See  for details.

---

###  Health Score

61

—

FairBetter than 99% of packages

Maintenance80

Actively maintained with recent releases

Popularity43

Moderate usage in the ecosystem

Community29

Small or concentrated contributor base

Maturity79

Established project with proven stability

 Bus Factor4

4 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~304 days

Recently: every ~256 days

Total

12

Last Release

164d ago

Major Versions

v1.0.0 → v2.0.02018-08-11

v2.2.0 → v3.0.02019-06-19

v3.0.0 → v4.0.02022-03-15

v4.2.0 → v5.0.02025-09-19

PHP version history (5 changes)v1.0.0PHP &gt;=5.5.9

v2.0.0PHP &gt;=5.6.99

v4.0.0PHP &gt;=7.2.9

v4.1.0PHP &gt;=7.4.0

v5.0.0PHP &gt;=8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/b94d9718c06ec7c3fd7a104bc44966fb7464b9ec7411582343ea35a7a6a85f08?d=identicon)[mediawiki](/maintainers/mediawiki)

![](https://www.gravatar.com/avatar/716c86d71cbf921e7912a505f89d799de398fc0a3af0bd4c8862834b2d642bd7?d=identicon)[wikimedia](/maintainers/wikimedia)

---

Top Contributors

[![umherirrender](https://avatars.githubusercontent.com/u/1174884?v=4)](https://github.com/umherirrender "umherirrender (16 commits)")[![jdforrester](https://avatars.githubusercontent.com/u/881572?v=4)](https://github.com/jdforrester "jdforrester (14 commits)")[![legoktm](https://avatars.githubusercontent.com/u/81392?v=4)](https://github.com/legoktm "legoktm (8 commits)")[![Krinkle](https://avatars.githubusercontent.com/u/156867?v=4)](https://github.com/Krinkle "Krinkle (8 commits)")[![anomiex](https://avatars.githubusercontent.com/u/1030580?v=4)](https://github.com/anomiex "anomiex (6 commits)")[![cscott](https://avatars.githubusercontent.com/u/156080?v=4)](https://github.com/cscott "cscott (6 commits)")[![tgr](https://avatars.githubusercontent.com/u/145412?v=4)](https://github.com/tgr "tgr (5 commits)")[![reedy](https://avatars.githubusercontent.com/u/67615?v=4)](https://github.com/reedy "reedy (4 commits)")[![arlolra](https://avatars.githubusercontent.com/u/123708?v=4)](https://github.com/arlolra "arlolra (2 commits)")[![ayg](https://avatars.githubusercontent.com/u/940446?v=4)](https://github.com/ayg "ayg (2 commits)")[![MatmaRex](https://avatars.githubusercontent.com/u/160413?v=4)](https://github.com/MatmaRex "MatmaRex (2 commits)")[![brightbyte](https://avatars.githubusercontent.com/u/664717?v=4)](https://github.com/brightbyte "brightbyte (2 commits)")[![Daimona](https://avatars.githubusercontent.com/u/38216014?v=4)](https://github.com/Daimona "Daimona (2 commits)")[![ZabeMath](https://avatars.githubusercontent.com/u/35405030?v=4)](https://github.com/ZabeMath "ZabeMath (1 commits)")[![Dreamy-Jazz](https://avatars.githubusercontent.com/u/75172487?v=4)](https://github.com/Dreamy-Jazz "Dreamy-Jazz (1 commits)")[![thiemowmde](https://avatars.githubusercontent.com/u/6576639?v=4)](https://github.com/thiemowmde "thiemowmde (1 commits)")[![urbanecm](https://avatars.githubusercontent.com/u/10050467?v=4)](https://github.com/urbanecm "urbanecm (1 commits)")[![DannyS712](https://avatars.githubusercontent.com/u/46829944?v=4)](https://github.com/DannyS712 "DannyS712 (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/wikimedia-timestamp/health.svg)

```
[![Health](https://phpackages.com/badges/wikimedia-timestamp/health.svg)](https://phpackages.com/packages/wikimedia-timestamp)
```

###  Alternatives

[masterminds/html5

An HTML5 parser and serializer.

1.8k242.8M229](/packages/masterminds-html5)[sabberworm/php-css-parser

Parser for CSS Files written in PHP

1.8k191.2M65](/packages/sabberworm-php-css-parser)[jms/metadata

Class/method/property metadata management in PHP

1.8k152.8M88](/packages/jms-metadata)[jms/serializer-bundle

Allows you to easily serialize, and deserialize data of any complexity

1.8k89.3M627](/packages/jms-serializer-bundle)[hassankhan/config

Lightweight configuration file loader that supports PHP, INI, XML, JSON, and YAML files

97513.5M170](/packages/hassankhan-config)[meyfa/php-svg

Read, edit, write, and render SVG files with PHP

54613.9M42](/packages/meyfa-php-svg)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
