Question

Time conversion from local time to UTC and vice versa

  • 6 November 2018
  • 7 replies
  • 194 views

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 time) to UTC
#
# Author: Egge-Jan Pollé, Tensing GIS Consultancy B.V.
# Date: 24 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

Badge +1

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

very useful little trick, thank you for sharing

Badge +2

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

Badge +7

@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?

Badge +13

@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)

Userlevel 2
Badge +21

@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)
Badge +7

@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