coords-to-timezone
v1.0.3
Published
Lookup timezone details from geographic coordinates. Returns IANA timezone identifier, UTC offset and timezone abbreviation for any lat/lon location.
Maintainers
Readme
coords-to-timezone
Lookup timezone details from geographic coordinates. Returns IANA timezone identifier, UTC offset, and timezone abbreviation for any lat/lon location.
Installation
npm install coords-to-timezoneUsage
const { getTimeZoneInfo } = require('coords-to-timezone');
const result = getTimeZoneInfo({ lat: 37.7749, lon: -122.4194 });
console.log(result);
// {
// timeZone: 'America/Los_Angeles',
// offset: 'UTC-08:00',
// abbreviation: 'PST'
// }API
getTimeZoneInfo({ lat, lon, date? })
| Parameter | Type | Required | Description |
|-----------|--------|----------|------------------------------------------|
| lat | number | ✅ | Latitude (-90 to 90) |
| lon | number | ✅ | Longitude (-180 to 180) |
| date | Date | ❌ | Date to use for offset/abbreviation (defaults to new Date()) |
Returns
| Field | Type | Description |
|---------------|--------|------------------------------------|
| timeZone | string | IANA timezone identifier (e.g. America/Los_Angeles) |
| offset | string | UTC offset (e.g. UTC-08:00) |
| abbreviation| string | Timezone abbreviation (e.g. PST) |
Examples
// New York
getTimeZoneInfo({ lat: 40.7128, lon: -74.0060 });
// { timeZone: 'America/New_York', offset: 'UTC-05:00', abbreviation: 'EST' }
// London
getTimeZoneInfo({ lat: 51.5074, lon: -0.1278 });
// { timeZone: 'Europe/London', offset: 'UTC+00:00', abbreviation: 'GMT' }
// Mumbai
getTimeZoneInfo({ lat: 19.0760, lon: 72.8777 });
// { timeZone: 'Asia/Kolkata', offset: 'UTC+05:30', abbreviation: 'IST' }
// With a specific date
getTimeZoneInfo({ lat: 37.7749, lon: -122.4194, date: new Date('2024-07-01') });
// { timeZone: 'America/Los_Angeles', offset: 'UTC-07:00', abbreviation: 'PDT' }Authors
- Rohit Saxena
- Leelavathi Sura
License
No License needed
