Building applications for global users? This guide covers everything about timezone conversion via API, including handling daylight saving time, timezone databases, and implementation examples in multiple programming languages.
Understanding Timezones
Timezones are regions that observe the same standard time. They're typically expressed as offsets from UTC (Coordinated Universal Time) and identified by names from the IANA timezone database.
Example: America/New_York is UTC-5 in winter and UTC-4 in summer (DST)
Daylight Saving Time
DST adds complexity to timezone handling:
Spring Forward
Clocks move forward, causing a "missing" hour in local time.
Fall Back
Clocks move backward, causing an ambiguous hour that occurs twice.
Regional Variations
Not all regions observe DST, and dates vary by country.
Using the Timezone Converter API
TinyFn provides a simple endpoint to convert between timezones:
GET https://api.tinyfn.io/v1/time/convert?time=2024-01-15T10:00:00&from=America/New_York&to=Europe/London
Headers: X-API-Key: your-api-key
{
"from": {
"timezone": "America/New_York",
"time": "2024-01-15T10:00:00-05:00",
"offset": "-05:00",
"is_dst": false
},
"to": {
"timezone": "Europe/London",
"time": "2024-01-15T15:00:00+00:00",
"offset": "+00:00",
"is_dst": false
}
}
Parameters
| Parameter | Type | Description |
|---|---|---|
time |
string | Time to convert (ISO 8601 format) |
from |
string | Source timezone (IANA name) |
to |
string | Target timezone (IANA name) |
Code Examples
JavaScript / Node.js
const response = await fetch(
'https://api.tinyfn.io/v1/time/convert?time=2024-01-15T10:00:00&from=America/New_York&to=Europe/London',
{ headers: { 'X-API-Key': 'your-api-key' } }
);
const result = await response.json();
console.log(result.to.time); // 2024-01-15T15:00:00+00:00
Python
import requests
response = requests.get(
'https://api.tinyfn.io/v1/time/convert',
params={
'time': '2024-01-15T10:00:00',
'from': 'America/New_York',
'to': 'Europe/London'
},
headers={'X-API-Key': 'your-api-key'}
)
result = response.json()
print(result['to']['time']) # 2024-01-15T15:00:00+00:00
cURL
curl "https://api.tinyfn.io/v1/time/convert?time=2024-01-15T10:00:00&from=America/New_York&to=Europe/London" \
-H "X-API-Key: your-api-key"
Common Use Cases
- Meeting Schedulers: Show meeting times in attendees' local timezones
- E-commerce: Display shipping times in customer's timezone
- Global Teams: Coordinate work across different timezones
- Event Platforms: Show event times in viewer's local time
- Travel Apps: Convert times for flight/hotel bookings
Best Practices
- Store in UTC: Always store times in UTC, convert only for display
- Use IANA names: Use full timezone names, not abbreviations
- Handle DST: Test your app during DST transitions
- User preferences: Let users set their preferred timezone
Try the Timezone Converter API
Get your free API key and start converting timezones in seconds.
Get Free API Key