Posted by : at

Category : javascript

Manipulating Date in Javascript

// function to convert epoch to date

function convertEpochToDate(date){

  let convertedDate = new Date(date);

  let day = convertedDate.getDate();

  let month = convertedDate.getUTCMonth() + 1;

  let year = convertedDate.getUTCFullYear();

  let dateString = (day <= 9 ? '0' + day : day) + '/' + (month <= 9 ? '0' + month : month) + '/' + year;

  return dateString;

}

// call the function

let a = convertEpochToDate(1565827200000);

console.log(a); // 15/08/2019

var date = new Date('2015-02-10T10:12:50.5000z');

date; 'Default format:'

date.toDateString();'Tue Feb 10 2015'

date.toLocaleDateString();'2/10/2015'

date.toGMTString(); 'GMT format' 

date.toISOString(); '2015-02-10T10:12:50.500Z' 

date.toLocaleString();'Local date Format '

date.toLocaleTimeString(); 'Locale time format '

date.toString('YYYY-MM-dd'); 'Tue Feb 10 2015 15:42:50'

date.toTimeString(); '15:42:50' 

date.toUTCString(); 'UTC format '

Related Posts