PHPackages                             jessedp/php-timezones - 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. jessedp/php-timezones

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

jessedp/php-timezones
=====================

Basic Timezone utilities aimed at Laravel

v0.2.3(3y ago)527.7k↓35.7%MITPHPPHP &gt;=7.2.0CI failing

Since Feb 20Pushed 3y ago2 watchersCompare

[ Source](https://github.com/jessedp/php-timezones)[ Packagist](https://packagist.org/packages/jessedp/php-timezones)[ RSS](/packages/jessedp-php-timezones/feed)WikiDiscussions main Synced 2d ago

READMEChangelog (6)Dependencies (2)Versions (9)Used By (0)

php-timezones
=============

[](#php-timezones)

[![Latest Version](https://camo.githubusercontent.com/f4321b2c813159e068aa131b176b070a7ee0afa2d8f20d4be82b4de9d7557368/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f6a6573736564702f7068702d74696d657a6f6e65732e7376673f7374796c653d666c61742d737175617265)](https://github.com/jessedp/php-timezones/releases)[![MIT Licensed](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Test Status](https://camo.githubusercontent.com/a0f9539caf4103ac6bf3de17e274580ad541b1049dcc79079e620864268bd199/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6a6573736564702f7068702d74696d657a6f6e65732f72756e2d746573742e796d6c3f6c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/jessedp/php-timezones/actions?query=workflow%3Arun-tests)[![Quality Score](https://camo.githubusercontent.com/f287a3e95f7722c2cf3037f62d34f89440415dbf1a8e5c99e6b45ec4596d6173/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f6a6573736564702f7068702d74696d657a6f6e65732e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/jessedp/php-timezones)[![Total Downloads](https://camo.githubusercontent.com/d18378934977452024b35e95f17fb96dbbd9592246a52c6cab3dd0306a8c9c98/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6a6573736564702f7068702d74696d657a6f6e65732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/jessedp/php-timezones)

A wrapper to enumerate PHP 5.6+, 7.x, 8.x timezones in a simplified way for use in various ways.

This is done with Laravel 5.5+ in mind - YMMV elsewhere.

Basics
------

[](#basics)

- Creates timezone arrays based on PHP's supported timezones with optional grouping by region
- Lists are sorted by offset from high (+14:00) to low (-11:00)
- Optionally group the arrays (multi-dim associated array) by region
    - sorting is the same, but only inside each region
- For either case, return those as:
    - php arrays for whatever use your heart desires
    - HTML select list
- 2 utility functions for converting to/from UTC

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

[](#installation)

You can install this package using [Composer](https://getcomposer.org).

```
$ composer require jessedp/php-timezones

Using version ^0.2.0 for jessedp/php-timezones
./composer.json has been updated
    ...
```

Usage
-----

[](#usage)

### 1. Render a timezone HTML Select list

[](#1-render-a-timezone-html-select-list)

The method `Timezones::create()` has three parameters:

```
Timezones::create($name, $selected, $opts);
```

- $name **required** - the *name* of the select element
- $selected - sets the selected value of list box, assuming the a value with the option exists
- $opts an array of options as key=&gt;value:
    - attr =&gt; *array* of key=&gt;value pairs to be included in the select element (ie, 'id', 'class', etc.)
    - with*regions =&gt; \_boolean* whether or not to use option groups for the regions/continents (defaults to false)
    - regions =&gt; array (of strings) specifying the region(s) to include

#### Basic Example

[](#basic-example)

```
Timezones::create('timezone');
```

Returns a string similar to:

```

  ...
  (GMT/UTC + 00:00) Abidjan
  (GMT/UTC + 00:00) Accra
  ...

```

#### "Selected" Example

[](#selected-example)

Same as above, but *Asia/Ho\_Chi\_Minh* will be selected by default

```
Timezones::create('timezone', 'Asia/Ho_Chi_Minh');
```

#### "Options" Example

[](#options-example)

You may also add multiple attributes with an array.

```
Timezones::create('timezone', null,
            ['attr'=>[
             'id'    => 'my_id',
             'class' => 'form-control'
            ]
        ]);
```

Which gives us:

```

    (GMT/UTC + 14:00)&nbsp;&nbsp;&nbsp;&nbsp;Pacific/Apia

    (GMT/UTC + 14:00)&nbsp;&nbsp;&nbsp;&nbsp;Pacific/Kiritimati

  ...

    (GMT/UTC + 08:00)&nbsp;&nbsp;&nbsp;&nbsp;Asia/Shanghai

    (GMT/UTC + 08:00)&nbsp;&nbsp;&nbsp;&nbsp;Asia/Singapore

    (GMT/UTC + 08:00)&nbsp;&nbsp;&nbsp;&nbsp;Asia/Taipei

  ...

    (GMT/UTC − 05:00)&nbsp;&nbsp;&nbsp;&nbsp;America/New York

  ...

```

#### "Regions/Grouping" Example

[](#regionsgrouping-example)

Say you want the option groups but only a couple regions...

```
Timezones::create('timezone',null,
                    ['attr'=>['class'=>'form-control'],
                    'with_regions'=>true,
                    'regions'=>['Africa','America']
                    ])
```

This will return a string similar to the following:

```

      (GMT/UTC + 03:00)&nbsp;&nbsp;&nbsp;&nbsp;Addis Ababa

      (GMT/UTC + 03:00)&nbsp;&nbsp;&nbsp;&nbsp;Asmara

    ...

    ...

      (GMT/UTC − 02:00)&nbsp;&nbsp;&nbsp;&nbsp;Noronha

    ...

      (GMT/UTC − 03:00)&nbsp;&nbsp;&nbsp;&nbsp;Argentina/Buenos Aires

    ...

      (GMT/UTC − 05:00)&nbsp;&nbsp;&nbsp;&nbsp;New York

    ...

```

### 2. Render a timezone array

[](#2-render-a-timezone-array)

You can also render timezone list as an array. To do so, just use the `Timezones::toArray()` method.

Example in Laravel:

```
$timezone_list = Timezones::toArray();
```

### 3. Utility methods

[](#3-utility-methods)

The package includes two methods that make it easy to deal with displaying and storing timezones, `convertFromUTC()` and `convertToUTC()` :

Each function accepts two required parameters and a third optional parameter dealing with the format of the returned timestamp.

```
    Timezones::convertFromUTC($timestamp, $timezone, $format);
    Timezones::convertToUTC($timestamp, $timezone, $format);
```

The first parameter accepts a timestamp, the second accepts the name of the timezone that you are converting to/from. The option values associated with the timezones included in the select form builder can be plugged into here as is. Alternatively, you can use any of [PHP's supported timezones](http://php.net/manual/en/timezones.php).

The third parameter is optional, and default is set to `'Y-m-d H:i:s'` , which is how Laravel natively stores datetimes into the database (the `created_at` and `updated_at` columns). If you're using this for display purposes, you may find including `'(e)'` in the format string which displays the timezone.

Thanks to
---------

[](#thanks-to)

This is based off some lovely work by:

-
-

The [Spatie group](https://github.com/spatie) and specifically the [laravel-analytics](https://github.com/spatie/laravel-analytics/) project I used as inspiration copied for structure

###  Health Score

32

—

LowBetter than 69% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity30

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 92.6% 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 ~371 days

Recently: every ~463 days

Total

6

Last Release

1198d ago

PHP version history (2 changes)v0.1.0PHP &gt;=5.4.0

v0.2.2PHP &gt;=7.2.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/77744?v=4)[jesse](/maintainers/jessedp)[@jessedp](https://github.com/jessedp)

---

Top Contributors

[![jessedp](https://avatars.githubusercontent.com/u/77744?v=4)](https://github.com/jessedp "jessedp (50 commits)")[![nathan-io](https://avatars.githubusercontent.com/u/25315716?v=4)](https://github.com/nathan-io "nathan-io (2 commits)")[![derUli](https://avatars.githubusercontent.com/u/1799239?v=4)](https://github.com/derUli "derUli (1 commits)")[![scrutinizer-auto-fixer](https://avatars.githubusercontent.com/u/6253494?v=4)](https://github.com/scrutinizer-auto-fixer "scrutinizer-auto-fixer (1 commits)")

---

Tags

laravelphptimezonelaraveltimezonestimezone

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/jessedp-php-timezones/health.svg)

```
[![Health](https://phpackages.com/badges/jessedp-php-timezones/health.svg)](https://phpackages.com/packages/jessedp-php-timezones)
```

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M346](/packages/psalm-plugin-laravel)[renatomarinho/laravel-page-speed

Laravel Page Speed

2.5k1.7M11](/packages/renatomarinho-laravel-page-speed)[vinkius-labs/laravel-page-speed

Laravel Page Speed

2.5k12.5k1](/packages/vinkius-labs-laravel-page-speed)[jackiedo/timezonelist

A small package use to create a timezone list box in Laravel

111648.2k1](/packages/jackiedo-timezonelist)[emargareten/inertia-modal

Inertia Modal is a Laravel package that lets you implement backend-driven modal dialogs for Inertia apps.

90142.9k](/packages/emargareten-inertia-modal)[wearepixel/laravel-cart

A cart implementation for Laravel

1374.8k](/packages/wearepixel-laravel-cart)

PHPackages © 2026

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