如何将UTC字符串格式化为MMMM DD,yyyy in JavaScript for Kore.ai

发布于 2025-02-03 18:05:23 字数 77 浏览 3 评论 0原文

我拥有的字符串:2021-11-02T00:00:00.000Z。 我需要将其显示为2021年11月2日。

有人可以帮助我吗?

The string I have : 2021-11-02T00:00:00.000Z .
I need to display this as November 02, 2021.

Could someone please help me with this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

離殇 2025-02-10 18:05:23

您可以在香草JS中做这样的事情

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

console.log(new Date('2021-11-02T00:00:00.000Z').toLocaleDateString("en-US", options));

You can do something like this in vanilla JS

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

console.log(new Date('2021-11-02T00:00:00.000Z').toLocaleDateString("en-US", options));

复古式 2025-02-10 18:05:23

您将要使用日期类提供的内容,这是一个完整的示例。

const date = new Date('2021-11-02T00:00:00.000Z')
const month = date.toLocaleString('default', {
  month: 'long'
})
const day = date.getDay()
const year = date.getFullYear()
console.log(`${month} ${day}, ${year}`)

You would want to use what Date class has provided, here's a complete example.

const date = new Date('2021-11-02T00:00:00.000Z')
const month = date.toLocaleString('default', {
  month: 'long'
})
const day = date.getDay()
const year = date.getFullYear()
console.log(`${month} ${day}, ${year}`)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文