2

I am getting Time stamp as "2020-03-02T05:50:31.000Z"

How to convert this to Normal Readable Format with Date and Time Zone

Logica
  • 977
  • 4
  • 16
  • 4
    What is `Normal Readable Format` to you? For me, you already have it. Also, what have you tried? Plenty of questions already deal with date/time formatting in JavaScript. – fredrik Mar 09 '20 at 07:01
  • I mean it as to normal time and date format – Nagasai ReactJumbo Mar 09 '20 at 07:03
  • 1
    use new Date("2020-03-02T05:50:31.000Z"), and then use different methods to get the date in format you want. – shubham-gupta Mar 09 '20 at 07:03
  • Does this answer your question? [Formatting the date time with Javascript](https://stackoverflow.com/questions/8847109/formatting-the-date-time-with-javascript) – Mohammad Faisal Mar 09 '20 at 07:05
  • That already follows normal [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) what format do you want it on? – fredrik Mar 09 '20 at 07:05
  • Please provide description or example of Normal Readable Format. search on stackoverflow will give you plenty of answers. *date format in js site:stackoverflow.com* – Chandan Mar 09 '20 at 07:13

4 Answers4

3

const parsedDate = new Date("2020-03-02T05:50:31.000Z");
console.log(parsedDate.toGMTString())
//"Mon, 02 Mar 2020 05:50:31 GMT"
console.log(parsedDate.toLocaleString())
//"3/2/2020, 11:20:31 AM"
console.log(parsedDate.toDateString(), parsedDate.toTimeString())
//Mon Mar 02 2020 11:20:31 GMT+0530 (India Standard Time)
2

In java-script above date format can be parsed by using Date.

Eg:

var date = new Date('2020-03-02T05:50:31.000Z');
1

I don't know what you mean readable format but you can use following methods:

new Date('2020-03-02T05:50:31.000Z').toLocaleString();
// outputs date according to user locale settings

Or you can use getYear, getMonth, getDay methods to get them and format date as you want

Malkhazi Dartsmelidze
  • 4,783
  • 4
  • 16
  • 40
-1

You can use moment.js for date time format and conversion.
Pass your date timestamp as below:

moment.parseZone("2020-03-02T05:50:31.000Z").format("DD-MM-YYYY hh:mm:ss z Z")

Modify format as you need ref mentioned here

Use in your code as mentioned here

Dipten
  • 1,031
  • 8
  • 16