Doug Black
Posts: 0
Joined: Wed Aug 14, 2013 11:36 am

Date with Javascript Undefined

Hi! I have a portion of my app that maps the date from the database. I have code to parse it so it only shows the Date and the Month.

When I run the test app in a browser, it works fine. However, when I test it on a mobile device (both in the browser, and as an IPA file), it shows "undefined NaN"

Here's the mapping:

Here's the code:
precode
var startTime = new Date(value);
startTimeMonth = startTime.getMonth();
//Get month
var month=new Array();
month[0]="January&quot
month[1]="February&quot
month[2]="March&quot
month[3]="April&quot
month[4]="May&quot
month[5]="June&quot
month[6]="July&quot
month[7]="August&quot
month[8]="September&quot
month[9]="October&quot
month[10]="November&quot
month[11]="December&quot
var startTimeMonthName = month[startTimeMonth];

//Get date and add suffix
startTimeDate = startTime.getDate();
var j = startTimeDate % 10;
switch(j)
{
case (j == 1 && startTimeDate != 11):
startTimeDateOrd = startTimeDate + "st&quot
break;
case (j == 2 && startTimeDate != 12):
startTimeDateOrd = startTimeDate + "nd&quot
break;
case (j == 3 && startTimeDate != 13):
startTimeDateOrd = startTimeDate + "rd&quot
break;
default:
startTimeDateOrd = startTimeDate + "th&quot
}

//And return it
//alert(startTimeMonthName + " " + startTimeDateOrd);
return startTimeMonthName + " " + startTimeDateOrd;
/code/pre

Any thoughts?

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

Date with Javascript Undefined

Hi Doug,

Please post a public link and tell how to reproduce this.

Doug Black
Posts: 0
Joined: Wed Aug 14, 2013 11:36 am

Date with Javascript Undefined

http://potomac.app.appery.io/

You can see the error by going to the Ministers Prayer Connect.

In a web browser, the dates under each name are there. On a mobile device, they come up as undefined.

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

Date with Javascript Undefined

Hello! The problem seems to be with data parser in Safari. Please replace prevar startTime = new Date(value);/pre with prevar startTime = new Date(value.replace(/-/g, '/').slice(0, value.indexOf(' ')));/pre

Doug Black
Posts: 0
Joined: Wed Aug 14, 2013 11:36 am

Date with Javascript Undefined

Perfect, thank you!

Return to “Issues”