Reputation: 41
Using date-fns, how it could be converted string like '2223' to time '22:23' using date-fns? I tried use parse method but it return 'Invalid Date'
const timeString = '2223';
parse(timeString, 'HH:mm', new Date())
Upvotes: 0
Views: 237
Reputation: 31371
Your template string says it has a :
in the input string which your timeString
doesnt, so you either have to change your timeString
to 22:23
or change your parse method to template to this: HHmm
Upvotes: 1