Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I format time to a dayjs object?

I have the following code


import dayjs from 'dayjs'

const abc = dayjs("09:00:00")
console.log(abc)

abc in console is

an invalid date

how can I make this into a valid date, the condition being the input is always going to be in format "09:00:00"

like image 804
Vikrant Bhat Avatar asked Nov 25 '25 13:11

Vikrant Bhat


1 Answers

To get this to work, you'll need to enable the CustomParseFormat plugin. Then you can specify a format string for dayjs to use. For example:

const abc = dayjs("09:00:00", "HH:mm:ss");
console.log(abc);

Will result in the following:

The result of abc

You can read about the different options for the format string at the dayjs documentation: https://day.js.org/docs/en/parse/string-format

like image 200
thatoddmailbox Avatar answered Nov 27 '25 03:11

thatoddmailbox



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!