0

While testing my program I noticed that, while the date works well on Chrome and it gives me a valid one, for Firefox I receive an Invalid Date while trying to run the following code:

var dateToConvert = $filter('date')(resourcehelper.getLocalDate(jm.logging.subordinatedElements[i].logTime), 'yyyy-MM-dd HH:mm:ss:sss');
var dateWithDifference = moment(dateToConvert).subtract(hourDifference, 'hours').format('YYYY-MM-DD HH:mm:ss:SSS');

Where "jm.logging.subordinatedElements[i].logTime" is a date which is equal to an unix format like this one: 1545092400027

The "hourDifference" variable is calculated like this:

var differenceOfHours = moment.utc(moment(localDate, 'YYYY-MM-DD HH:mm:ss:SSS').diff(moment(serverDate, 'YYYY-MM-DD HH:mm:ss:SSS'))).format("HH");
return parseInt(differenceOfHours);

Where both the localDate and the serverDate have the following format: "2018-12-18 02:20:00:043". The hourDifference always gives me "00", and 0 after parseInt, no matter the hour difference between two dates, on firefox.

While all of this works on Chrome without problems, as I said they don't do in firefox. My question is, how should I make my date be recognizable without changing the "2018-12-18 02:20:00:043" format? (since I must display the date in this format to the final user).

chazsolo
  • 7,873
  • 1
  • 20
  • 44
Artyomska
  • 1,309
  • 5
  • 26
  • 53
  • Possible duplicate of [What are valid Date Time Strings in JavaScript?](https://stackoverflow.com/questions/51715259/what-are-valid-date-time-strings-in-javascript) – str Dec 23 '18 at 13:10

1 Answers1

0

I fixed the problem in the end by changing the date format in an ISO compatible one. The reason for why the dates weren't working in firefox was because of the more restrictive date parsing that firefox has compared to chrome, so for firefox and momentJS a ISO or RFC2822 compatible format must be used.

I used for my dates this one 2013-02-08 24:00:00.000

Artyomska
  • 1,309
  • 5
  • 26
  • 53