Home > Software design >  How to convert this type of date time format to readable string
How to convert this type of date time format to readable string

Time:11-11

I get a datetime value from api in this format: 2022-11-11T08:52:01.000000Z I need to convert it to readable form with javascript.

I need this in any readable form, both time and date should be included

CodePudding user response:

Try it:

import moment from "moment"

const time = "2022-11-11T08:52:01.000000Z"
const formattedDate = moment(time, "DD/MM/YYYY")
console.log(formattedDate)

More information: https://momentjs.com/docs/#/parsing/string-format/

CodePudding user response:

Take a look at the date-fns library:

https://date-fns.org/v2.29.3/docs/format

Easy way of converting dates to any format you desire.

warning: pseudo code

import {format} from 'date-fns'

const date = 2022-11-11T08:52:01.000000Z
const formatedDate = format(date, DD MM YY hh:mm)

CodePudding user response:

you need to install the the following package

npm install moment or yarn add moment

or you can use

npm install dayjs or yarn add dayjs

then after format your time as the following

if you choose to use moment do this

import moment from 'moment';
moment('2022-11-11T08:52:01.000000Z').format("DD/MM/YY")

and if you choose to use dayjs use

 import dayjs from "dayjs";
 dayjs('2022-11-11T08:52:01.000000Z').format("YYYY-MM-DDTHH:mm:ss") 

for more info go to their official documentation momentjs and for dayjs

  • Related