js date time string code example
Example 1: js string to date
var myDate = new Date("2013/1/16");
var str = "2013/1/16";
var strToDate = new Date(str);
Example 2: javascript format date
var options = { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' };
var today = new Date();
console.log(today.toLocaleDateString("en-US"));
console.log(today.toLocaleDateString("en-US", options));
console.log(today.toLocaleDateString("hi-IN", options));
Example 3: string date to date in javascript
var ts = '1471793029764';
ts = Number(ts);
var date = new Date(ts);
var invalidDate = new Date('1471793029764');
Example 4: get date format javascript
const handleDate = (dataD) => {
let data= new Date(dataD)
let month = data.getMonth() + 1
let day = data.getDate()
let year = data.getFullYear()
if(day<=9)
day = '0' + day
if(month<10)
month = '0' + month
const postDate = year + '-' + month + '-' + day
return postDate
}