I wrote the code like below and show like photo.
but
I want to show only "hour and minutes" like
14:56
Is it possible to display only hours and minutes like this?
If it is possible, how can I show it?
Json
{
"time_start": "2022-12-22 14:56:00",
"time_end": "2022-12-22 16:56:00",
}
React.js
{schedules.map(schedule => (
<div className="each_scheduled" key={schedule.id}>
<div>
<p className="scheduled_p">Time</p>
<p className="scheduled_p">{schedule.time_start} - {schedule.time_end}</p>
</div>
</div>
))}
4
Answers
I don’t know if that’s the best approach, but you can split the date from the time like this:
You can use slice.
I would strongly advice you to work with a library dedicated for dates and times, it will make your life a lot easier, I highly suggest
luxon
with which your code could then look like so:
If the format of your time strings is fixed, you could use the slice() function to slice the strings at appropriate indexes.
Changing your code as follows will achieve the desired result: