Home > Net >  How to get only date from full date time?
How to get only date from full date time?

Time:07-10

Hello I am getting one date from backend like this-

const date = Tue Jul 26 2022 20:58:08 GMT 0600 (Bangladesh Standard Time)

From this date need only 2022-07-26 format

Can you help me. I am using momentjs.

CodePudding user response:

Here's how you can do it with a custom Moment format:

date.format("YYYY-MM-DD")

CodePudding user response:

If you're using momentjs, try using their formats:

moment(date).format("YYYY-MM-DD")

It should return this value - 2022-07-09

CodePudding user response:

I don't know about momentjs but you can easily do this in vanilla

var dtDate = new Date()
var sDate = dtDate.toISOString().split("T")[0]

CodePudding user response:

you can do with pure Javascript easily as code below:

const date = new Date();

console.log(date.toLocaleDateString('bn-BD')) // => '৯/৭/২০২২'

hope it helps you.

  • Related