You can use the string.replace
method along with a regular expression to reformat the date string. Here's an example code snippet that shows how to do this:
index.tsx167 chars5 lines
In the above code, we're using the replace
method to replace the hyphens with dots in the date string. The regular expression ^(\d{2})-(\d{2})-(\d{4})$
matches the date string in the format of dd-mm-yyyy
and captures the day, month, and year as separate groups. The replacement string '$1.$2.$3'
then puts these groups back together separated by dots, resulting in the desired date format of dd.mm.yyyy
.
gistlibby LogSnag