4

Esri recommends that databases are in UTC time. And if I’ve got this right, unless you set a time zone in your layer, you are entering a date in a date field as UTC. Mostly this is fine.You understand that the date refers to Pacific time for instance. You understand the date comes back to you the same value you put into the field. The problem comes when the browser or iOS or whatever device automatically localizes on initialization of a Date object.

Problem: When ArcGIS Server returns a date, it sends milliseconds since epoch UTC (unix time). However, the Javascript Date object always creates a localized date when you use that to instantiate a Date object, e.g. Pacific Daylight Time, moving it back -7 hours. Thus, March 16 0:00am in the data becomes March 15 5:00pm — one day early. How do you get the actual time storedin the database?

PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Nov 6, 2012 at 17:40

1 Answer 1

3

Quick and easy solution, keep everything in UTC. Use the javascript getUTC functions to return UTC time, which will remove the localization offset on the date. (Yes, you could break this out into templates and formats, but really, how many different date formats do you need for most apps?)

http://www.spatialexception.org/posts/arcgis-server-and-javascript-dates

function getUTCDateYYYYMMDD(milliSecUnix) {
var d, mm, dd;
if (milliSecUnix) {
 d = new Date(milliSecUnix);
 mm = d.getUTCMonth() + 1;
 dd = d.getUTCDate();
 return (d.getUTCFullYear() + "-" +
 ((mm < 10) ? "0" + mm : mm) + "-" +
 ((dd < 10) ? "0" + dd : dd));
}
else {
 return "";
}

}

answered Nov 6, 2012 at 17:40

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.