开发者

How to get date in specific locale with JavaScript?

开发者 https://www.devze.com 2022-12-27 15:34 出处:网络
I need to get the date in a specific locale using JavaScript - not necessarily the user\'s locale. How can I do this?

I need to get the date in a specific locale using JavaScript - not necessarily the user's locale. How can I do this?

I did so开发者_StackOverflowme research and found date.getUTCMonth() and date.getUTCDate(). How can I use this or something else to get the date in a certain locale?


You can use toLocaleDateString:

From the MDN documentation:

The new locales and options arguments let applications specify the language whose formatting conventions should be used and allow to customize the behavior of the function.

const event = new Date();

const options = { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' };

console.log(event.toLocaleDateString('de-DE', options));
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号