Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I am working on a site that is using version 2.6 of the Esri Javascript API. I have an info window that displays some date information, and the date is one day behind the date in the database. For example:

If I identify a feature in ArcMap, the date returned is 8/15/2007. When I query for the same feature through the Rest endpoint I get 2007/08/15 00:00:00 UTC. When I identify the feature in the web application, the date returned is 8/14/2007.

In the javascript code I am formatting the date as follows:

${SALEDT:DateFormat(selector: 'date', fullYear: true)}

What is causing this, and what can I do to have the correct date returned?

share|improve this question
    
<format dateformat="shortDate" useutc="true"/> –  Brad Nesom Feb 14 '12 at 19:51
    
I had the same problem with flex. The above gave me correct data. –  Brad Nesom Feb 14 '12 at 21:10
1  
@BradNesom flex != JavaScript –  Derek Swingley Feb 14 '12 at 22:28
    
@BradNesom I saw a forum post with that yesterday, but the time formatting options are different in javascript. –  Timothy Michael Feb 15 '12 at 3:41

1 Answer 1

up vote 5 down vote accepted

Specify local: true in your date formatting function:

${SALEDT:DateFormat(selector: 'date', local: true, fullYear: true)}

Mintx's answer explains why you need to do this. More information on formatting info window/popup content is available in the help: Format info window content.

Edit: Use DateString, not DateFormat to specify the local option:

${SALEDT:DateString(local: true, hideTime: true)}

Edit 2: Thanks to the mods, here's the answer originally posted my Mintx that I refereced above:

You've got it mostly right, you just need to change the code to reflect the correct time zone. Since the feature you're reading from is a UTC timestamp, the JavaScript code is converting to your timezone, which (assuming you're in the US) will be 4 to 7 hours earlier than midnight of 8/15/2007, which is why it's returning one day earlier.

Edit 3: I threw together a quick, hacky way to do this with a custom formatting function: jsfiddle.net/yEkjm There is probably a better way to do this...I'm no expert on handling dates with JS.

share|improve this answer
    
Thanks Derek. I put local: true in the formatting function and am still getting dates one day behind. I verified that I have dojo.require("dojo.date.locale") - is there anything else I need? I verified that the setting/code isn't being cached. –  Timothy Michael Feb 14 '12 at 18:22
1  
That's my mistake, I used DateFormat in my answer and it should be DateString. I've edited my answer to show the correct syntax. –  Derek Swingley Feb 14 '12 at 21:30
    
I tried using DateString earlier today, but I need the date in mm/dd/yyyy format, and DateString returns the date as "Tue August 14 2007." –  Timothy Michael Feb 14 '12 at 22:33
    
@Tim if you want fine grained control over the date format, we're back to DateFormat. In my testing, features retrieved from a service that stores dates as UTC are automatically converted to the client's timezone when displayed. –  Derek Swingley Feb 14 '12 at 23:02
    
Thanks Derek. You're right, they are being converted to my time zone - that's why they're one day earlier. Is there a way to force the dates to be returned as UTC, since that date is the correct one? –  Timothy Michael Feb 15 '12 at 15:16

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.