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
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>
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()