Imp3ll
Imp3ll

Reputation: 41

How conver string of numbers to time using date-fns?

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

Answers (1)

LeeLenalee
LeeLenalee

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

Related Questions