How to format a date and write square brackets in dayjs?

39 Views Asked by At

In dayjs, I want to get the following date time string:

25-01-2024 [17:29]

However, when writing square brackets in the format method it's showing

25-01-2024 HH:mm

How to escape square brackets in dayjs?

import dayjs from 'dayjs'

export const formatDateTime = (dateString: string) => {
  const parsedDate = dayjs(dateString)
  const formattedDate = parsedDate.format('DD-MM-YYYY [HH:mm]')
  return formattedDate
}

1

There are 1 best solutions below

1
Konrad On BEST ANSWER

This works:

dayjs().format('DD-MM-YYYY [[]HH:mm]')

But I hope there is a better solution