what is the difference between the parse() methods and gettime() in javascript ???

gettime() => La méthode getTime() renvoie la valeur numérique correspondant au temps pour la date renseignée, d'après le temps universel (c'est-à-dire relative à UTC, une mesure donnée par getTime() sera indépendante du fuseau horaire sur lequel on se trouve). Cette valeur numérique est le nombre de millisecondes écoulées depuis le premier janvier 1970 à minuit UTC. parse() =>The Date.parse() method parses a string representation of a date, and returns the number of milliseconds since January 1, 1970, 00:00:00 UTC or NaN if the string is unrecognized or, in some cases, contains illegal date values (e.g. 2015-02-31). please I did not understand the difference between them, can you explain to me ???

7/9/2019 12:04:19 PM

program programing

7 Answers

New Answer


This is a good question indeed. The result seems the same but the accuracy (compatibility) is different. 1. A simple answer will be, to use getTime() instead of parse(). 2. A detail explanation : 2.1 Date.parse() https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/parse QUOTE = `It is not recommended to use Date.parseas until ES5, parsing of strings was entirely implementation dependent. There are still many differences in how different hosts parse date strings, therefore date strings should be manually parsed (a library can help if many different formats are to be accommodated).`; In short, because parse is a method of Date object, accepting a string of date representation. However data representation can be very different. For example, 1/2/2019 has two interpretation : Jan 2nd VS Feb 1st. This will cause unnoticeable wrong milliseconds. 2.2 Date.prototype.getTime() https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getTime


Welcome, if you don't mind, I would like to elaborate a bit more on the different interpretation, but not from a programming perspective. Now, suppose I have issued a Sales Contract to my customer, I want to tell that the finish time is Oct 9th, so based on my local practice of d/m/y, I put down 9/10/2019. Now, September comes, my customer can say : "Based on our local practice of m/d/y, this contract dues on Sept 10th, so your overdue should be fined! " So, it is always safer to use the eng short form on sales document when handling things such as international trade.


/* continue after word limit exceed */ on the other hand, getTime is a prototypical method. Prototypical method means that the method is called under prototypical instance. Since the object is already a Date object, there is no ambuity for the error possible when using Date.parse


yes, this is the culture of SoloLearn Q&A forum to share information generously. When you progress your learning, you can contribute in Q&A also. because by answering question, you need to organize your thoughts to phrase the explanation, and it's a good process of learning too ~


thank you very much <h1> <strong> :) :) :) </strong> </h1>


thank you. It's good to have people sharing information generously and without monopoly, thank you


yes, you're right :)