PHPackages                             fachrel/laravel-timezone-by-city - 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. fachrel/laravel-timezone-by-city

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

fachrel/laravel-timezone-by-city
================================

Laravel package to get timezone by city

v1.0.2(1y ago)09MITPHP

Since Jan 11Pushed 1y agoCompare

[ Source](https://github.com/fachrel/laravel-timezone-by-city)[ Packagist](https://packagist.org/packages/fachrel/laravel-timezone-by-city)[ Docs](https://github.com/fachrel/laravel-timezone-by-city)[ RSS](/packages/fachrel-laravel-timezone-by-city/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)Dependencies (1)Versions (4)Used By (0)

Laravel Timezone by City
========================

[](#laravel-timezone-by-city)

[![Latest Version on Packagist](https://camo.githubusercontent.com/919cf0c1894b35d837c6deb2bf3b0867481e2ae48232da5bc2a72ccd6f0a0513/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f696c68616d7269736b792f6c61726176656c2d74696d657a6f6e652d62792d636974792e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ilhamrisky/laravel-timezone-by-city)[![MIT Licensed](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Total Downloads](https://camo.githubusercontent.com/425ae52887eb99b83bac9edf85e76fbf2e394ed55240a5115aaaa66a402bbca2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f696c68616d7269736b792f6c61726176656c2d74696d657a6f6e652d62792d636974792e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ilhamrisky/laravel-timezone-by-city)

Introduction
------------

[](#introduction)

Laravel Get Timezone by City package provides a simple way to retrieve timezone information for cities around the world. It utilizes Carbon for date and time manipulation. This README will guide you on how to install and use the package in your Laravel project.

Data Source
-----------

[](#data-source)

The city data provided by this package is sourced from the GeoNames Gazetteer, available at [GeoNames Gazetteer](https://www.geonames.org/). GeoNames is a geographical database that covers all countries and contains over eleven million place names. As of the last update on February 16, 2024, it provides information for 146,892 cities worldwide.

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

[](#installation)

Require this package with composer using the following command:

```
composer require ilhamrisky/laravel-timezone-by-city
```

Usage
-----

[](#usage)

Import the namespace and instantiate the class in your Laravel controller or service

```
use IlhamriSKY\GetTimeZoneByCity\GetTimeZoneByCity;

$timeZoneByCity = new GetTimeZoneByCity();
```

Example
-------

[](#example)

### Example 1: Check if a city exists in the dataset

[](#example-1-check-if-a-city-exists-in-the-dataset)

```
$cityToCheck = 'New York City';
$cityExists = $timeZoneByCity->cityExists($cityToCheck);
// $cityExists will be a boolean indicating whether 'New York City' exists in the dataset
echo "Does $cityToCheck exist? " . ($cityExists ? 'Yes' : 'No');
```

### Example 2: Get a list of all cities available in the dataset

[](#example-2-get-a-list-of-all-cities-available-in-the-dataset)

```
$allCities = $timeZoneByCity->getAllCities();
// $allCities will be an array containing names of all cities
echo "All Cities: " . implode(', ', $allCities);
```

### Example 3: Get all data for a specific city

[](#example-3-get-all-data-for-a-specific-city)

```
$cityDetails = $timeZoneByCity->getAllData('London');
// $cityDetails will be an array containing details for 'London'
echo "Details for London: " . json_encode($cityDetails);
```

### Example 4: Get the timezone for a specific city

[](#example-4-get-the-timezone-for-a-specific-city)

```
$cityTimeZone = $timeZoneByCity->getTimeZone('Tokyo');
// $cityTimeZone will be a string containing the timezone for 'Tokyo'
echo "Timezone for Tokyo: " . $cityTimeZone;
```

### Example 5: Get the UTC offset for a specific city

[](#example-5-get-the-utc-offset-for-a-specific-city)

```
$cityUtcOffset = $timeZoneByCity->getTimeUTC('Sydney');
// $cityUtcOffset will be a string containing the UTC offset for 'Sydney'
echo "UTC Offset for Sydney: " . $cityUtcOffset;
```

### Example 6: Get the latitude and longitude for a specific city

[](#example-6-get-the-latitude-and-longitude-for-a-specific-city)

```
$cityLatLong = $timeZoneByCity->getTimeLatLong('Paris');
// $cityLatLong will be an array containing 'lat' and 'lng' for 'Paris'
echo "Latitude and Longitude for Paris: " . json_encode($cityLatLong);
```

### Example 7: Get a list of cities based on their country code

[](#example-7-get-a-list-of-cities-based-on-their-country-code)

```
$countryCode = 'US';
$citiesInCountry = $timeZoneByCity->getCitiesByCountry($countryCode);
// $citiesInCountry will be an array containing names of cities in the United States
echo "Cities in $countryCode: " . implode(', ', $citiesInCountry);
```

### Example 8: Get the current time in a specified city's timezone

[](#example-8-get-the-current-time-in-a-specified-citys-timezone)

```
$currentTimeInCity = $timeZoneByCity->getCurrentTimeInCity('Berlin');
// $currentTimeInCity will be a Carbon instance representing the current time in Berlin's timezone
echo "Current Time in Berlin: " . ($currentTimeInCity ? $currentTimeInCity->toDateTimeString() : 'City not found');
```

### Example 9: Get the city based on latitude and longitude coordinates

[](#example-9-get-the-city-based-on-latitude-and-longitude-coordinates)

```
$latitude = 40.7128;
$longitude = -74.0060;
$matchingCity = $timeZoneByCity->getCityByCoordinates($latitude, $longitude);
// $matchingCity will be an array containing details for the city matching the coordinates
echo "City at ($latitude, $longitude): " . json_encode($matchingCity);
```

### Example 10: Convert time between two cities' timezones

[](#example-10-convert-time-between-two-cities-timezones)

```
$sourceCity = 'Los Angeles';
$destinationCity = 'London';
$convertedTime = $timeZoneByCity->convertTimeBetweenCities($sourceCity, $destinationCity, 'Y-m-d H:i:s');
// $convertedTime will be a string containing the converted time in London's timezone
echo "Converted Time from $sourceCity to $destinationCity: " . ($convertedTime ?? 'Cities not found');
```

### Example 11: Compare local time and city time

[](#example-11-compare-local-time-and-city-time)

```
$city = 'Semarang';
$compareTime = $timeZoneByCity->compareLocalTimeWithCityTime($city);

// $compareTime will be a array containing the compare local time and city time
echo "Time in {$city}: {$compareTime['city_datetime']}\n";
echo "Time in local timezone: {$compareTime['local_datetime']}\n";
echo "Time difference: {$compareTime['time_difference']['hours']} hours, {$compareTime['time_difference']['minutes']} minutes, {$compareTime['time_difference']['seconds']} seconds\n";
```

License (MIT License):
----------------------

[](#license-mit-license)

This package is released under the MIT License, which allows you to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the software. The only condition is that the above copyright notice and this permission notice shall be included in all copies or substantial portions of the software.

Feel free to contribute, create issues, or submit pull requests to enhance the functionality or fix any bugs.

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance42

Moderate activity, may be stable

Popularity4

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity40

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 60% 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 ~3 days

Total

3

Last Release

481d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/04b264206beb45b66c237cb57cca340b3713c2c00086af78381723f8b00f6493?d=identicon)[fachrel](/maintainers/fachrel)

---

Top Contributors

[![fachrel](https://avatars.githubusercontent.com/u/64237717?v=4)](https://github.com/fachrel "fachrel (6 commits)")[![IlhamriSKY](https://avatars.githubusercontent.com/u/18723904?v=4)](https://github.com/IlhamriSKY "IlhamriSKY (4 commits)")

---

Tags

laravelcitytimezone

### Embed Badge

![Health badge](/badges/fachrel-laravel-timezone-by-city/health.svg)

```
[![Health](https://phpackages.com/badges/fachrel-laravel-timezone-by-city/health.svg)](https://phpackages.com/packages/fachrel-laravel-timezone-by-city)
```

###  Alternatives

[jamesmills/laravel-timezone

Timezone storage and retrieval for Laravel

698764.1k12](/packages/jamesmills-laravel-timezone)[whitecube/laravel-timezones

Store UTC dates in the database and work with custom timezones in the application.

106106.2k](/packages/whitecube-laravel-timezones)[tapp/filament-timezone-field

Filament timezone field.

55276.6k4](/packages/tapp-filament-timezone-field)[glhd/laravel-timezone-mapper

Timezone mapper for Laravel

45284.4k](/packages/glhd-laravel-timezone-mapper)[dipeshsukhia/laravel-country-state-city-data

Country State City Data Provider

8230.8k](/packages/dipeshsukhia-laravel-country-state-city-data)[omar-haris/filament-timezone-field

A Laravel Filament component that enables users to choose a specific timezone grouped by regions, with support for multiple languages.

1613.5k1](/packages/omar-haris-filament-timezone-field)

PHPackages © 2026

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