typescript date format yyyy-mm-dd code example

Example 1: javascript format date yyyy-mm-dd

let today = new Date()
today.toISOString().split('T')[0]

Example 2: javascript format date yyyy-mm-dd

// yyyy-mm-dd
new Date().toISOString().slice(0, 10)

Example 3: change the way Date.now().toString() is logged

var date = Date.parse('Sun May 11,2014');

function format(date) {
  date = new Date(date);

  var day = ('0' + date.getDate()).slice(-2);
  var month = ('0' + (date.getMonth() + 1)).slice(-2);
  var year = date.getFullYear();

  return year + '-' + month + '-' + day;
}

console.log(format(date));

Example 4: js date format yyyy-mm-dd

yourDate.toISOString().split('T')[0]

Example 5: javascript format date object to yyyy-mm-dd

const yourDate = new Date()
yourDate.toISOString().split('T')[0]

Tags:

Java Example