开发者

How to get date in specific locale with JavaScript?

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜