Select to view content in your preferred language

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

110
2
Tuesday
Clubdebambos
MVP Regular Contributor
4 2 110

 

Epoch times are littered throughout the JSON behind the scenes in ArcGIS Online, from created and modified datetimes to usage statistics and even in feature attributes. It is important to know how to convert these to a more readable format. Below, we look at converting to a date, and you can find more conversion options from the Python docs here.

 

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

## Access ArcGIS Online
agol = GIS("home") # authenticate with "pro" or alternative

## Access a content item with an Item ID
item = agol.content.get("ITEM_ID")

## (optional) Print item properties to screen to see some date properties such
## as created and modified
print(json.dumps(item, indent=4))

## (optional) You can also access the properties individually
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)

 

2 Comments
StephanieM1
Esri Contributor

Thanks so much for this!! So helpful!

Just in case anyone runs into any issues with the sample code:

  • Line 1 is supposed to be-> from arcgis.gis import GIS
  • You'll want to add a line 20-> print(created_date) like in the video
Clubdebambos
MVP Regular Contributor

Thanks for pointing out @StephanieM1, I have updated the code snippet.

Contributors
About the Author
Glen Bambrick is GIS Consultant with extensive experience utilising skills for GIS project management, quality map production, data management, geospatial analysis, standardisation, and workflow automation across a range of industries such as agriculture, oil & gas, telecommunications and engineering. Going beyond map production there is a passion for the technologies behind GIS, the databases, the programming languages, the analysis and statistical output, and continued professional development associated with GIS. You will mainly find me contributing in the Python and ArcGIS API for Python Communities.