How to convert time to different timezone in a workflow

Here's how you can generate a timestamp based on a specific timezone.  In this example, we use -7 as the timezone offset.

# setup timezone offset

import DateConversion

 

TIME_ZONE_OFFSET = -7  

TIME_OFFSET = timedelta(hours=TIME_ZONE_OFFSET)

 

def get_current_iso_time():

   dtnow = datetime.datetime.now()

   dtutcnow = datetime.datetime.utcnow()

   delta = dtnow - dtutcnow

   hh,mm = divmod((delta.days * 24*60*60 + delta.seconds + 30) // 60, 60)

   return "%s%+03d:%02d" % (dtnow.isoformat(), hh, mm)

 

# get current time in iso format

now = DateConversion.to_py_datetime(get_current_iso_time())

 

# Get current time in UTC

now_utc = now.astimezone(DateConversion.UTC())

 

# Offset current time with Time Zone above to prepare the charts

now_w_offset = now.astimezone(DateConversion.UTC())+TIME_OFFSET