The Be Sure Blog

Code Snippets | Problem Solving | Tips & Tricks

The Be Sure Blog banner

Convert a date to dd.mm.yyyy (German date layout)

posted on 10.12.2022 by Below Surface in "JavaScript"

Your date may currently look like:

2022-10-25

All you need to convert it to the german format (dd.mm.yyyy) is:

const yourDate = "2022-10-25";
const convertedDate = new Date(yourDate).toLocaleString('de-DE').split(",")[0];

The new Date() method converts your date from string to date format and then converts it to the german format with the .toLocateString('de-DE') method. The .split() method is added to only take the part before the comma and time, that would be included. Your output should now look like:

25.10.2022

Tags:

javascript
date
string method

More posts of this category

How to sort an array by string value

One way to sort an array alphabetically by a string value

JavaScript