Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

javascript parse date dd/mm/yyyy hh:mm:ss

let dtStr = "16/03/2010 09:55:35"

console.log(strToDate(dtStr));  // Tue Mar 16 2010 09:55:35

function strToDate(dtStr) {
  if (!dtStr) return null
  let dateParts = dtStr.split("/");
  let timeParts = dateParts[2].split(" ")[1].split(":");
  dateParts[2] = dateParts[2].split(" ")[0];
  // month is 0-based, that's why we need dataParts[1] - 1
  return new Date(+dateParts[2], dateParts[1] - 1, +dateParts[0], timeParts[0], timeParts[1], timeParts[2]);
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #javascript #parse #date
ADD COMMENT
Topic
Name
2+3 =