PHPackages                             rarst/wpdatetime - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. rarst/wpdatetime

AbandonedArchivedLibrary[Utility &amp; Helpers](/categories/utility)

rarst/wpdatetime
================

Extension of PHP’s DateTime and DateTimeZone classes for WordPress context.

0.4(6y ago)6283.9k↓65%1MITPHPPHP &gt;=5.5.10

Since Nov 15Pushed 5y ago1 watchersCompare

[ Source](https://github.com/Rarst/wpdatetime)[ Packagist](https://packagist.org/packages/rarst/wpdatetime)[ RSS](/packages/rarst-wpdatetime/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependencies (2)Versions (8)Used By (0)

WpDateTime — DateTime extension for WordPress
=============================================

[](#wpdatetime--datetime-extension-for-wordpress)

WpDateTime is an extension of PHP’s [`DateTime`](http://php.net/manual/en/class.datetime.php) and [`DateTimeZone`](http://php.net/manual/en/class.datetimezone.php) classes for WordPress context.

It makes it easy to instance time objects from WordPress posts and produce localized output with correct format and time zone handling.

Retired
-------

[](#retired)

The project is **retired** in favor of native WordPress 5.3+ functions:

- `WpDateTime::createFromPost()` — [`get_post_datetime()`](https://developer.wordpress.org/reference/functions/get_post_datetime/)
- `WpDateTime->formatI18n()` — [`wp_date()`](https://developer.wordpress.org/reference/functions/wp_date/)
- `WpDateTimeZone::getWpTimezone()` — [`wp_timezone()`](https://developer.wordpress.org/reference/functions/wp_timezone/)

Installation
------------

[](#installation)

Require as [Composer](https://getcomposer.org/) package in your project:

```
composer require rarst/wpdatetime
```

Usage
-----

[](#usage)

### `WpDateTime` and `WpDateTimeImmutable`

[](#wpdatetime-and-wpdatetimeimmutable)

Classes extend `DateTime` and `DateTimeImmutable` respectively and retain their full functionality.

You can use shared `WpDateTimeInterface` to hint for both.

#### Methods

[](#methods)

- `WpDateTime::createFromPost()` creates object instance from WP post. Time zone defaults to current WP setting.
- `WpDateTime->formatI18n()` outputs formatted and localized date in object’s time zone.
- `WpDateTime->formatDate()` outputs in current WP date format.
- `WpDateTime->formatTime()` outputs in current WP time format.

#### Example

[](#example)

```
use Rarst\WordPress\DateTime\WpDateTime;

$date = WpDateTime::createFromPost( get_post() );

printf(
	'Posted on: %s',
	$date->format( DATE_RFC3339 ),
	$date->formatDate()
);
// Posted on: Ноябрь 7, 2014
```

### `WpDateTimeZone`

[](#wpdatetimezone)

Class extends `DateTimeZone`.

#### Methods

[](#methods-1)

- `WpDateTimeZone::getWpTimezone()` static method creates object instance from current WordPress settings. Defaults to `timezone_string` option and falls back to `gmt_offset` one.

#### Example

[](#example-1)

```
use Rarst\WordPress\DateTime\WpDateTimeZone;

// Timezone string.
var_dump( WpDateTimeZone::getWpTimezone()->getName() );
// string(11) "Europe/Kiev"

// GMT offset.
var_dump( WpDateTimeZone::getWpTimezone()->getName() );
// string(6) "+02:00"
```

Tests
-----

[](#tests)

Tests use [Brain Monkey](https://brain-wp.github.io/BrainMonkey/) (included in dependencies) and PHPUnit 7 (not included).

```
composer install
phpunit
```

License
-------

[](#license)

MIT

###  Health Score

33

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity37

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

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 ~183 days

Recently: every ~172 days

Total

7

Last Release

2418d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/689ddc4f33541ac4a001d247e560f8805d219a95e7e42a16e0d22b9409f385cb?d=identicon)[Rarst](/maintainers/Rarst)

---

Top Contributors

[![Rarst](https://avatars.githubusercontent.com/u/737584?v=4)](https://github.com/Rarst "Rarst (34 commits)")

---

Tags

datetimewordpresswordpresstimedatetimezone

### Embed Badge

![Health badge](/badges/rarst-wpdatetime/health.svg)

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

###  Alternatives

[brick/date-time

Date and time library

3663.8M106](/packages/brick-date-time)[knplabs/knp-time-bundle

Making your dates and durations look sensible and descriptive

6339.5M56](/packages/knplabs-knp-time-bundle)[league/period

Time range API for PHP

7335.8M24](/packages/league-period)[aeon-php/calendar

PHP type safe, immutable calendar library

20810.4M16](/packages/aeon-php-calendar)[dater/dater

Compact PHP library for working with date/time in different formats &amp; timezones.

14484.2k](/packages/dater-dater)[icanboogie/datetime

Extends the features of PHP DateTime and DateTimeZone

51352.4k3](/packages/icanboogie-datetime)

PHPackages © 2026

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