<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Cross Browser date wackiness in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/cross-browser-date-wackiness/m-p/173166#M16030</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;try something like this&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
var m = moment(1300406400000);
console.log(m.toDate());
// result is Thu Mar 17 2011 17:00:00 GMT-0700 (Pacific Daylight Time)
console.log(m.format('M/DD/YYYY'));
// result is "3/17/2011"
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 08:57:41 GMT</pubDate>
    <dc:creator>ReneRubalcava</dc:creator>
    <dc:date>2021-12-11T08:57:41Z</dc:date>
    <item>
      <title>Cross Browser date wackiness</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/cross-browser-date-wackiness/m-p/173163#M16027</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;On the page I've been developing, I've been populating a datagrid with attributes from a feature layer. A few of the attributes are date fields. I found out the hard way about the the format of date values returned through the API so I looked for a function to properly format my dates and times back into xx/xx/xxxx and xx:xx ampm formats.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I settled on the following functions which use dojo:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;function formatDate(value){
 var inputDate = new Date(value);
 return dojo.date.locale.format(inputDate, {
&amp;nbsp;&amp;nbsp; selector: 'date',
&amp;nbsp;&amp;nbsp; datePattern: 'MM/dd/yyyy' 
 });
}

function formatTime(value){
 var inputTime = new Date(value);
 return dojo.date.locale.format(inputTime, {
&amp;nbsp;&amp;nbsp; selector: 'date',
&amp;nbsp;&amp;nbsp; datePattern: 'K:mm a' 
 });
}&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The routines are used in a formatter() function for one of my columns in the datagrid like this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;var rowdata = this.grid.getItem(rowIndex);
var theClosureDate = rowdata.dateCl;

alert(formatDate(theClosureDate));&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here's where it gets weird- I've been doing my development and debugging with Firefox and the dates displayed are correct. I just loaded the page in Chrome and IE-8 and the dates displayed are "NaN".&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Does anyone have a conversion function they can share which works across all browsers? It would be especially great if it also handled the UTC/local time difference. I realized that these routines don't.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank you!&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Steve&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 17 Aug 2012 17:28:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/cross-browser-date-wackiness/m-p/173163#M16027</guid>
      <dc:creator>SteveCole</dc:creator>
      <dc:date>2012-08-17T17:28:42Z</dc:date>
    </item>
    <item>
      <title>Re: Cross Browser date wackiness</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/cross-browser-date-wackiness/m-p/173164#M16028</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Dates are my kryptonite, but to I've had really good luck with moment.js&lt;/SPAN&gt;&lt;BR /&gt;&lt;A href="http://momentjs.com/"&gt;http://momentjs.com/&lt;/A&gt;&lt;BR /&gt;&lt;SPAN&gt;I was having issues between IE and Chrome parsing dates, this little lib helped simplify the process.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;The draw for me was it could easily handle asp.net json dates. Maybe it could help you out.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 17 Aug 2012 21:15:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/cross-browser-date-wackiness/m-p/173164#M16028</guid>
      <dc:creator>ReneRubalcava</dc:creator>
      <dc:date>2012-08-17T21:15:46Z</dc:date>
    </item>
    <item>
      <title>Re: Cross Browser date wackiness</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/cross-browser-date-wackiness/m-p/173165#M16029</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks Rene for the the link to moment.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm feeling a bit dense but I can't seem to get it to work with the dates from my data. The dates are being returned through a query so the "format" of the information coming back is a series of numbers such as "1300406400000". I tried using moment like this but it doesn't work:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;var temp = moment(new date(theClosureDate));
alert(temp.format('M/DD/YYYY'));&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 08:57:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/cross-browser-date-wackiness/m-p/173165#M16029</guid>
      <dc:creator>SteveCole</dc:creator>
      <dc:date>2021-12-11T08:57:38Z</dc:date>
    </item>
    <item>
      <title>Re: Cross Browser date wackiness</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/cross-browser-date-wackiness/m-p/173166#M16030</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;try something like this&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
var m = moment(1300406400000);
console.log(m.toDate());
// result is Thu Mar 17 2011 17:00:00 GMT-0700 (Pacific Daylight Time)
console.log(m.format('M/DD/YYYY'));
// result is "3/17/2011"
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 08:57:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/cross-browser-date-wackiness/m-p/173166#M16030</guid>
      <dc:creator>ReneRubalcava</dc:creator>
      <dc:date>2021-12-11T08:57:41Z</dc:date>
    </item>
    <item>
      <title>Re: Cross Browser date wackiness</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/cross-browser-date-wackiness/m-p/173167#M16031</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Well HALLELUJAH! I have solved the mystery of date formatting!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Your suggestion, Rene, still didn't work for me so I kept playing with it. If I manually typed things in within the javascript console, it would work. If I used the same thing within my javascript function, it would not. This got me thinking that perhaps the date returned via the query was a &lt;/SPAN&gt;&lt;STRONG&gt;string&lt;/STRONG&gt;&lt;SPAN&gt; instead of a number.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;To test it, I tried adding the "parseInt" function:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;alert(new Date(parseInt(rowdata.dateCl)));&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Lo and behold- it now works in Chrome and STILL works in Firefox. Thank god! That was maddening. Thanks again, Rene for helping me out!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 20 Aug 2012 16:09:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/cross-browser-date-wackiness/m-p/173167#M16031</guid>
      <dc:creator>SteveCole</dc:creator>
      <dc:date>2012-08-20T16:09:27Z</dc:date>
    </item>
  </channel>
</rss>

