-4

The date format that I get from an API is 24/09/2020 22:58:58 but i want that to change in Yesterday at 10:58 PM in Moment.js

PS: i tried but didn't work out

1
  • 1
    Please include any code that you've tried so far and didn't work Commented Sep 25, 2020 at 9:08

2 Answers 2

1

You could display like that using moment calendar time

const date = moment("24/09/2020 22:58:58", "DD/MM/YYYY HH:mm:ss").calendar()

console.log(date)
<script src="https://momentjs.com/downloads/moment.min.js"></script>

Sign up to request clarification or add additional context in comments.

Comments

0

Look at the Calendar time section on the Moment.js landing page

moment().subtract(1, 'days').calendar(); will give you for example Yesterday at 10:58 PM by subtracting a day from the current time and converting into calendar time

This is if you want to get the same time as now but yesterday. If you want to get a specific time, just pass in to the moment() as an argument then convert to calendar() like so:

moment('24/09/2020 22:58:58', 'DD/MM/YYYY HH:mm:ss').calendar()

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.