string to date javascript dd/mm/yyyy code example
Example 1: javascript convert date to yyyy-mm-dd
const formatYmd = date => date.toISOString().slice(0, 10);
formatYmd(new Date());
Example 2: javascript convert date from mm/dd/yyyy to yyyymmdd
var yourdate = date.split("/").reverse().join("-");
Example 3: convert date dd/mm/yyyy to date object js
DateParts = data.split("/");
new Date(+DateParts[2], DateParts[1] - 1, +DateParts[0]).setUTCHours(
0,
0,
0,
0
)
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
}