Answers for "javascript date parse mm/dd/yyyy"

13

mm dd yyyy how to get date in this format in javascript

var today = new Date();
var dd = String(today.getDate()).padStart(2, '0');
var mm = String(today.getMonth() + 1).padStart(2, '0'); //January is 0!
var yyyy = today.getFullYear();

today = mm + '/' + dd + '/' + yyyy;
document.write(today);
Posted by: Guest on February-27-2020
0

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]);
}
Posted by: Guest on October-14-2021

Code answers related to "javascript date parse mm/dd/yyyy"

Code answers related to "Javascript"

Browse Popular Code Answers by Language