Skip to main content
Question

Time conversion from local time to UTC and vice versa

  • November 6, 2018
  • 7 replies
  • 345 views

egge
Contributor
Forum|alt.badge.img+14
  • Contributor

Hi Community,

 

No question, just a tip to share...

 

For a workflow we have to check for new observations in an ArcGIS Online Feature Service and send an email to relevant stakeholders. AGOL time is in UTC whereas the email is send in local time. To notify the right times we had to convert the AGOL time to local time and the email time to UTC. We use AttributeCreators for that. Below we share the code used for these conversions:

 

# Convert input time (in UTC) to local time
#
# Author: Egge-Jan Pollé, Tensing GIS Consultancy B.V.
# Date: 24 October 2018
#
# The date we get from ArcGIS Online (SRNL_CREATED_DATE) is in UTC.
# To convert it to local time we first have to set the time zone to utc:
#
# Step 1: @TimeZoneSet(@Value(SRNL_CREATED_DATE),utc)
#
# Next we can convert it form utc to local:
#
# Step 2: @TimeZoneSet(<Output from Step 1>,local,convert)
#
# We can nest this like below:

@TimeZoneSet(@TimeZoneSet(@Value(SRNL_CREATED_DATE),utc),local,convert)

# Convert input time (in local timeto UTC
#
# Author: Egge-Jan Pollé, Tensing GIS Consultancy B.V.
# Date24 October 2018
#
# The date we get with @DateTimeNow() is in local time.
# To convert it to UTC first we have to set the time zone to local:
#
# Step 1: @TimeZoneSet(@DateTimeNow(),local)
#
# Next we can convert it form local to utc:
#
# Step 2: @TimeZoneSet(<Output from Step 1>,utc,convert)
#
# We can nest this like below:

@TimeZoneSet(@TimeZoneSet(@DateTimeNow(),local),utc,convert)

7 replies

Forum|alt.badge.img+1
  • November 21, 2018

This simple one line fix really made my day! Thank you Egge-Jan Pollé! :D Neatly done


  • December 18, 2019

very useful little trick, thank you for sharing


dorgin
Contributor
Forum|alt.badge.img+3
  • Contributor
  • March 18, 2020

Thank you so much for posting this, it's very helpful


benvk
Contributor
Forum|alt.badge.img+7
  • Contributor
  • April 3, 2020

@egge I am attempting to convert to local Sydney, AUSTRALIA time, from the stored ArcGIS Online UTC.

I have done the below in the Attribute Creator, it does not seem to work for me, I am getting NULL in the newly created columns. Any ideas what I am doing wrong?


jelle
Contributor
Forum|alt.badge.img+16
  • Contributor
  • April 3, 2020
benvk wrote:

@egge I am attempting to convert to local Sydney, AUSTRALIA time, from the stored ArcGIS Online UTC.

I have done the below in the Attribute Creator, it does not seem to work for me, I am getting NULL in the newly created columns. Any ideas what I am doing wrong?

@benvk: maybe try to change (@Value(@Value(shift_end)) to (@Value(shift_end)


ebygomm
Influencer
Forum|alt.badge.img+31
  • Influencer
  • April 3, 2020
jelle wrote:

@benvk: maybe try to change (@Value(@Value(shift_end)) to (@Value(shift_end)

Agree, you have an extra @Value in there

try

@TimeZoneSet(@TimeZoneSet(@Value(shift_start),local),utc,convert)

benvk
Contributor
Forum|alt.badge.img+7
  • Contributor
  • April 4, 2020
jelle wrote:

@benvk: maybe try to change (@Value(@Value(shift_end)) to (@Value(shift_end)

Spot on, I am now seeing results in the AttributeCreator fields. The results are all out by +2HR, is there a way I can define the timezone I am in or something? I am assuming it is detecting something nearby, but not exactly +11 like I am here. Any thoughts?


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings