ArcGIS Desktop

  • ArcGIS Pro
  • ArcMap

  • My Profile
  • Help
  • Sign Out
ArcGIS Desktop

ArcGIS Online

The mapping platform for your organization

ArcGIS Desktop

A complete professional GIS

ArcGIS Enterprise

GIS in your enterprise

ArcGIS Developers

Tools to build location-aware apps

ArcGIS Solutions

Free template maps and apps for your industry

ArcGIS Marketplace

Get apps and data for your organization

  • Documentation
  • Support
Esri
  • Sign In
user
  • My Profile
  • Sign Out

ArcMap

  • Home
  • Get Started
  • Map
  • Analyze
  • Manage Data
  • Tools
  • Extensions

TimeZoneInfo

  • Summary
  • Discussion
  • Syntax
  • Method Overview
  • Methods
  • Code sample

Summary

The TimeZoneInfo class can be used to read or assign a time zone to a Python datetime object.

Discussion

Native datetime objects are not time zone aware. By assigning a time zone to a datetime object, time zone-related operations can be performed. For example, you can use the time zone associated with a time value and convert it to another time zone.

Syntax

TimeZoneInfo
 (time_zone_id)
ParameterExplanationData Type
time_zone_id

A valid time zone ID. A list of available time zone IDs can be obtained from the ListTimeZones function.

String

Method Overview

MethodExplanation
tzname (dt)

Returns the time zone name corresponding to the Python datetime object, dt, as a string.

Methods

tzname (dt)
ParameterExplanationData Type
dt

A reference to a Python datetime object.

(The default value is None)

DateTime

Return Value

Data TypeExplanation
String

The time zone name corresponding to the datetime object, dt.

Returns the time zone name corresponding to the datetime object, dt, as a string.

Code sample

TimeZoneInfo example 1

The following script applies a 'Pacific Standard Time' time zone to a Python datetime object. It then loops through each month to demonstrate how the time zone name will change to 'Pacific Daylight Time' during the summer in observance of Daylight Savings Time.

import arcpy
import datetime

tzinfo = arcpy.time.TimeZoneInfo('Pacific Standard Time')

time = datetime.datetime(2011, 1, 1, tzinfo=tzinfo)

for delta in range(1, 13):
    next_date = time + arcpy.time.EsriTimeDelta(1 * delta, "months")
    print next_date, tzinfo.tzname(next_date)
TimeZoneInfo example 2

The following script demonstrates how to convert a datetime value in Pacific Standard Time to Eastern Standard Time.

import arcpy
import datetime

from_tzinfo = arcpy.time.TimeZoneInfo('Pacific Standard Time')
target_tzInfo = arcpy.time.TimeZoneInfo('Eastern Standard Time')
from_time = datetime.datetime.now(from_tzinfo)
print "target_time =", str(from_time.astimezone(target_tzInfo))

ArcGIS Desktop

  • Home
  • Documentation
  • Support

ArcGIS

  • ArcGIS Online
  • ArcGIS Desktop
  • ArcGIS Enterprise
  • ArcGIS
  • ArcGIS Developer
  • ArcGIS Solutions
  • ArcGIS Marketplace

About Esri

  • About Us
  • Careers
  • Esri Blog
  • User Conference
  • Developer Summit
Esri
Tell us what you think.
Copyright © 2021 Esri. | Privacy | Legal