You can use the replace()
method to format the date string. Here's an example:
index.tsx154 chars4 lines
Explanation:
/^(\d{2}).(\d{2}).(\d{4})$/
matches the string in the format dd.mm.yyyy
, where dd
, mm
, yyyy
are two-digit day, month, and year values respectively.(\d{2})
, (\d{2})
, (\d{4})
using parentheses.$2
), followed by a slash (/
), then the first group ($1
), another slash, and finally the third group ($3
), resulting in the desired mm/dd/yyyy
format.gistlibby LogSnag