how parse/unParse TimeWindowStart1 VRP

2582
2
Jump to solution
06-25-2016 07:44 PM
CloudingSoft
Occasional Contributor

Hello

in http://resources.arcgis.com/en/help/arcgis-rest-api/#/Vehicle_Routing_Problem_service/02r3000000n400... There are fields of type TIME, but do not quite understand as I have to enter them.

for example:

orders={"features":[{"geometry":{"x":-122.51,"y":37.7724},"attributes":{"TimeWindowStart1":1355245200000,"TimeWindowEnd1":1355274000000,"MaxViolationTime1":0}}

as I can know that this value corresponds date: 1355245200000?

and how I can convert a date format that I must enter the API: 06/25/2016 08: 15hs AM?

0 Kudos
1 Solution

Accepted Solutions
RandyBurton
MVP Alum

The time used is epoch time (or Unix time) - the number of milliseconds since 1 Jan 1970 (usually in UTC, so you may need to convert to/from local time).  Search for code that will convert to and from this time.  Here's a python sample.

import datetime, time
epoch_time = int(time.mktime(datetime.datetime.now().timetuple()) * 1000)
print epoch_time
print time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(int(epoch_time/1000)))
my_time = 1355245200000
print time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(int(my_time/1000)))
print int(time.mktime(time.strptime('2012-12-11 08:00:00','%Y-%m-%d %H:%M:%S'))* 1000)

View solution in original post

2 Replies
RandyBurton
MVP Alum

The time used is epoch time (or Unix time) - the number of milliseconds since 1 Jan 1970 (usually in UTC, so you may need to convert to/from local time).  Search for code that will convert to and from this time.  Here's a python sample.

import datetime, time
epoch_time = int(time.mktime(datetime.datetime.now().timetuple()) * 1000)
print epoch_time
print time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(int(epoch_time/1000)))
my_time = 1355245200000
print time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(int(my_time/1000)))
print int(time.mktime(time.strptime('2012-12-11 08:00:00','%Y-%m-%d %H:%M:%S'))* 1000)
CloudingSoft
Occasional Contributor

hello

It was so simple to multiply by a thousand when sending dates on the api and divide by a thousand when I print dates to return the api.

thank you very much for your help

0 Kudos