I'm currently trying to format a timestamp in JavaScript. Sadly, the result is a bit strange. This is the date I'm trying to format:
Thu May 23 2019 17:34:18 GMT+0200 (Mitteleuropäische Sommerzeit)
And this is how it should looks like after formatting it:
23.05.2019
This is my code:
j = myDateString;
console.log(j.getUTCDate() + "." + j.getUTCMonth() + "." + j.getUTCFullYear());
But when I run my code, this is the result:
23.4.2019
getUTCMonth() starts from 0 (January), fix it by adding one.
console.log(j.getUTCDate() + "." + (j.getUTCMonth() + 1) + "." + j.getUTCFullYear());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With