Convert ArcGIS Online Epoch Time to DD/MM/YYYY or other format using the ArcGIS API for Python

Table of Contents

The Video

Introduction

Learn how to convert ArcGIS Online epoch timestamps into readable date formats (DD/MM/YYYY) using the ArcGIS API for Python and Python’s built-in datetime module. Below is a step-by-step guide how to access item properties from ArcGIS Online, extract epoch values, and format them into clean, human-readable dates. Perfect for GIS developers, analysts, and anyone automating ArcGIS workflows with Python.

Discover the power of automation and script-based operations to efficiently manage content in ArcGIS Online. Throughout this course, you will gain practical, hands-on experience with using the ArcGIS API for Python to perform a wide range of content management tasks with ease, such as creating Folders and Groups and managing content within them.

arcgis modules

The API provides access to your organisations ArcGIS Online via the GIS class in the gis module. This GIS class is the gateway to ArcGIS Online. We will also utilise the datetime module from the standard Python library to help convert the epoch to a date, along with the json module to print item properties to screen in a more readable friendly format.

				
					## provides access to ArcGIS Online
from arcgis.gis import GIS

## allows us to convert the epoch to date
from datetime import datetime

## print readable propertues
import json
				
			

Accessing ArcGIS Online

Our first port of call is to access your ArcGIS Online via the GIS class. There are a handful of ways to achieve access, if you are logged into your ArcGIS Online in ArcGIS Pro you can simply use "home", otherwise, another common way is to provide the ArcGIS Online URL, followed by your username and password.
				
					## Access AGOL
agol = GIS("home")
				
			
				
					## Access AGOL
agol = GIS(
    url = "https://your_organisation.maps.arcgis.com/",
    username = "Your_Username",
    password = "Your_Password"
)
				
			

Get the Item Object

The get() method from the ContentManager returns an Item object representing that content item from ArcGIS Online. For examples, a Feature Service, Dashboard, Form, Experience Builder, Shapefile are all types of item content.

				
					## Access the Item
item = agol.content.get("ITEM_ID")
				
			

Optional: Print the item properties

Print the item properties to see which properties store an epoch as the date (created and modified for example).

				
					print(json.dumps(item, indent = 4))

print(item.created)
				
			

Convert the ArcGIS Online Epoch to Date

We divide the epoch by 1000 and use the String Format Time function to produce a date representing DD/MM/YYYY. See here for more formatting options.

				
					created_date = datetime.utcfromtimestamp(item.created / 1000).strftime("%d/%m/%Y")

print(created_date)
				
			

Geospatial Professionals, GIS Analysts, and enthusiasts will discover the power of automation and script-based operations to efficiently interact and update WebMaps in ArcGIS Online. Throughout this course, you will gain practical, hands-on experience in leveraging the ArcGIS API for Python to perform a wide range of WebMap tasks with ease.

We will dissect WebMaps for all that they are and by the end of this course you will be comfortable with manipulating the JSON, which is the behind the scenes configuration of a WebMap, to produce scripts for workflows where there is currently no API Python method, such as grouping layers.

All the code in one place

You can find the entire code workflow below with links to important components in the documentation that were used.

				
					from arcgis.gis import GIS
from datetime import datetime
import json

################################################################################
## API Reference Links:
##  https://developers.arcgis.com/python/latest/api-reference/arcgis.gis.toc.html#gis
##  https://developers.arcgis.com/python/latest/api-reference/arcgis.gis.toc.html#arcgis.gis.ContentManager.get
##  https://developers.arcgis.com/python/latest/api-reference/arcgis.gis.toc.html#item
##
################################################################################

## Access AGOL
agol = GIS("home")

## Access the WebMap Item
item = agol.content.get("ITEM_ID")

################################################################################
## Print the Item Properties
################################################################################

print(json.dumps(item, indent = 4))

print(item.created)

################################################################################
## Convert ArcGIS Online Epoch to DD/MM/YYYY
################################################################################

created_date = datetime.utcfromtimestamp(item.created / 1000).strftime("%d/%m/%Y")

print(created_date)

################################################################################
print("\nSCRIPT COMPLETE")
				
			

Leave a Comment