Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
0
rated 0 times [  1] [ 1]  / answers: 1 / hits: 19017  / 6 Years ago, tue, march 13, 2018, 12:00:00

I have multiple date's for example(25-12-2017) i need them to be converted to milliseconds by javascript


More From » date

 Answers
15

One way is to use year, month and day as parameters on new Date




new Date(year, month [, day [, hours [, minutes [, seconds [, milliseconds]]]]]);




You can prepare your date string by using a function.



Note: Month is 0-11, that is why m-1



Here is a snippet:





function prepareDate(d) {
[d, m, y] = d.split(-); //Split the string
return [y, m - 1, d]; //Return as an array with y,m,d sequence
}

let str = 25-12-2017;
let d = new Date(...prepareDate(str));

console.log(d.getTime());





Doc: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date


[#54959] Thursday, March 8, 2018, 6 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
kiley

Total Points: 733
Total Questions: 118
Total Answers: 94

Location: Liechtenstein
Member since Wed, Dec 8, 2021
3 Years ago
;