I'm using date-fns in a React project.
const sampleText = 'Tue Aug 03 2021 18:49:11 GMT+0800';
const sampleDate = new Date(sampleText);
format(sampleDate, 'hh:mm')
This returns '06:49'. How can I get this to return '18:49' instead?
I'm using date-fns in a React project.
const sampleText = 'Tue Aug 03 2021 18:49:11 GMT+0800';
const sampleDate = new Date(sampleText);
format(sampleDate, 'hh:mm')
This returns '06:49'. How can I get this to return '18:49' instead?
The format tokens for date-fns can be found here: https://date-fns.org/v2.28.0/docs/format
const sampleText = 'Tue Aug 03 2021 18:49:11 GMT+0800';
const sampleDate = new Date(sampleText);
format(sampleDate, 'HH:mm')
This is also another option which uses 'kk:mm:ss' format:
const sampleText = 'Tue Aug 03 2021 18:49:11 GMT+0800';
const sampleDate = new Date(sampleText);
format(sampleDate, 'kk:mm:ss')
HH:mm
. –
Cystoscope ss
from the format. See the documentation referenced above. –
Columbuscolumbyne © 2022 - 2025 — McMap. All rights reserved.
HH:mm
– LaalandsampleText.substring(16,21)
or as local timenew Date('Tue Aug 03 2021 18:49:11 GMT+0800').toLocaleString('en',{hour:'2-digit', minute:'2-digit', hour12:false})
. Oh sorry, no library… – Osgood