0

I am new to UI (User Interface) coding and I have date from json as "2021-02-28 00:00:00". But while writing to the xlsx I don't want the date in string form. And this is what I have tried.

variable = new Date("2021-02-28 00:00:00")

Which give the date object as below

Sun Feb 28 2021 00:00:00 GMT+0530 (India Standard Time)

But I want the date to be in below format [should be still a date object not a string]

28 Feb 2021 00:00:00
Ice Bear
  • 701
  • 2
  • 18
lee_na
  • 11
  • 1
  • "But i want the date to be in below format [should be still a date object not a string]" - I think you don't understand how dates are represented inside computers. – Dai Jan 04 '21 at 04:47
  • @AlonEitan the thing if i format the date the typeof the date converts to string. And i am looking for a sloution to keep the typeof date as object so that after writing into the xlsx file user can filter the dates – lee_na Jan 04 '21 at 06:38

1 Answers1

0

you can do it using Date object but there's many lines to do that.

I handle all my date formatting with moment.

e.g. moment('2021-02-28 00:00:00').format('DD MMM YYYY hh:mm:ss')

console.log(moment('2021-02-28 00:00:00').format('DD MMM YYYY HH:mm:ss'))
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.1/moment.min.js"></script>
Someone Special
  • 6,546
  • 5
  • 25
  • 50