Dùng toISOString() và cắt 10 ký tự đầu: date.toISOString().slice(0,10). Kết quả là YYYY-MM-DD theo UTC.
Ví dụ
<html>
<head>
<title>Định dạng Date yyyy-mm-dd trong JavaScript</title>
</head>
<body>
<script>
var date = new Date();
var res = date.toISOString().slice(0,10);
document.write(res);
</script>
</body>
</html>
Kết quả
2018-12-15
Lưu ý: Kết quả theo UTC. Nên dùng getFullYear(), getMonth()+1, getDate() để format theo giờ địa phương.