-1

I have a below date format need to convert it as

console.log(new Date(startDate)).toISOString();
console.log(new Date(endDate)).toISoString();

I need an output like this 20180928T00000 but which return 2018-11-01T00:00:00.000Z this format.

Current Output:
// startDate=2018-11-01T00:00:00.000Z
 //endDate=2018-12-01T00:00:00.000Z

Expected 
// StartDate=20181101T000000 
// endDate=20181201T0000000';
Mohamed Sahir
  • 2,482
  • 8
  • 40
  • 71

1 Answers1

0

You could use Moment.js, however if it is just a once off and you do not want to import the whole library, I would suggest using regex to remove all none letters/numbers, then JS slice() method to remove last character.

const date = '2018-11-01T00:00:00.000Z'
const result = date.replace(/[^A-Za-z0-9]+/g,'').slice(0, -1)
console.log(result) // 20181101T000000000
Benni Russell
  • 354
  • 2
  • 7