I recieve this date format from strapi 2021-09-01T15:21:39.862Z how can i transform it to a DD/MM/YYYY format ?
<div class="post-date-article">{{ formatMyDate(article.published_at) }}</div>
formatMyDate(value){
if (value) {
return value;
}
}
Strapi are providing a date in ISO 8601 format, which is easy to parse using the JavaScript date object.
I'd suggest using Date.toLocaleDateString() to format the input date
as DD/MM/YYYY. Using a locale of 'en-GB' will format the supplied date in this way.
You can pass other locales such as 'de-DE' to format the date in another way if you wish.
function formatMyDate(value, locale = 'en-GB') {
return new Date(value).toLocaleDateString(locale);
}
const timestamp = '2021-09-01T15:21:39.862Z';
console.log('Timestamp:', timestamp);
console.log('Formatted date:', formatMyDate(timestamp));
.as-console-wrapper { max-height: 100% !important; top: 0; }
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