Joe Sharples
Posts: 0
Joined: Mon Aug 18, 2014 1:31 pm

date format ios

The _createdAt field is mapped to a label on a list.

I have the js on the mapping.

pre
var date = new Date(value);
var hour = date.getHours();
date.setHours(hour);
var diff = ((((new Date()).getTime() - date.getTime()) / 1000)-3600); //-3600 is for time difference reasons
var day_diff = Math.floor(diff / 86400);

console.log("dif type "+typeof diff);
console.log("dif "+ diff);

console.log("day diff type "+typeof day_diff);
console.log("day diff "+ day_diff);

if (day_diff < 1){

if (diff < 60){
return "just now";
}

if (diff < 120){
return "1m";
}

if (diff < 3600){
min = Math&#46;floor( diff / 60 );
return min+ "m";

Code: Select all

 } 

if (diff < 7200){
return "1hr";
}

Code: Select all

 if (diff < 86400){ 

hr = Math&#46;floor( diff / 3600 );
return hr + "hr";
}

}

else {
return day_diff + "d";
}
/pre

When I test it on chrome it works as expected.
but when i test it on the appery test app on my iphone it returns 'NaNd' for every item.

Therefore it is not recognising day_diff to be a number.
I added
pre console&#46;log(typeof day_diff);
console&#46;log(typeof diff); /pre
to this code and it showed
'number
number'.

I also tried using parseInt(), but that didnt work either

how do i get it to recognise it as a number on iphone?
please note, it works on chrome correctly, but not the appery test app iphone.

Thank you for all your help so far.

Bruce Stuart
Posts: 0
Joined: Fri Oct 24, 2014 4:42 am

date format ios

Joe,

Without getting too much into your challenge - i recently developed a date-math library for an app I built where I had to do a lot of date manipulation.

This set of functions - cans a lot of the challenges people have with date manipulation. You can use it on the server or client side. Since it runs on the server side - it's also free from challenges where some things work with some browsers and not others.

Let me know if it helps.

Bruce

http://the-software-studio.com/javasc...

bahar.wadia
Posts: 0
Joined: Wed Aug 07, 2013 2:05 am

date format ios

I have the same problem, I think.

I am trying to take a date stored in the database, pass it to the the Date() object and then show the formatted date from the Date object. When I test it on Chrome, it works fine, but when I test it on an actual device, I get NaN.

Return to “Issues”