jquery - Momentjs, compare utc dates -
okay, loop through array of times comes server in following format:
2014-04-14t13:00:00z 2014-04-14t13:15:00z 2014-04-14t13:30:00z
now want catch item next now.
for (var j = 0; j < array.times.length; j++) { if ((moment(array.times[j])) > moment()) { // tried new date(), isafter(), unix(), utc() ... " // got item } };
this works, couldn´t catch timezone.
time-format comes comes server utc, right?
need locale time...!? or iam totally wrong?
in germany got +2 hours timezone offset.
your date strings in iso utc format, dates created them have different time depending on time zone. if create moment("2014-04-14t13:30:00z")
, have local time of 15:30 in case. sample code may working correctly, don't know requirements.
if want strings interpreted local time, easiest solution drop "z" @ end:
for (var j = 0; j < myarray.length; j++) { var datestring = myarray[j].substr(0, myarray[j].length - 1); if (moment(datestring) > moment()) { console.log(datestring); console.log(moment(datestring).todate()); break; } }
Comments
Post a Comment