如何从moment js中提取国家名称以添加到对象中

发布于 2025-01-14 12:14:14 字数 445 浏览 2 评论 0原文

我有以下内容,我正在格式化时刻日期并将其存储到对象中,如下所示

async date(){
 var today=Moment() **// today gets stored as Wed Mar 16 2022 12:05:07 GMT+0200 (Standard Time)'**
var date= today.format("dddd,D MMM YYYY"); /**/ date gets stored as Wednesday,16 Mar 2022**
var name= **how do i add what the name of the country is thats been returned after the GMT+0200 so it would be Standard Time**
}

是否有一个格式选项可以将国家/地区名称分配给对象? 那么变量名将存储国家/地区?

I have the following where i am formatting the moment date and storing it into an object as follows

async date(){
 var today=Moment() **// today gets stored as Wed Mar 16 2022 12:05:07 GMT+0200 (Standard Time)'**
var date= today.format("dddd,D MMM YYYY"); /**/ date gets stored as Wednesday,16 Mar 2022**
var name= **how do i add what the name of the country is thats been returned after the GMT+0200 so it would be Standard Time**
}

is there a format option that i can assign the Country name to an object?
so the variable name will store the country?

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

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

发布评论

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

评论(1

鹿童谣 2025-01-21 12:14:14

您可以尝试这样获取国家/地区名称,

const countryName = moment.tz.guess(true);

“猜测”将返回浏览器区域。

要获取浏览器区域以外的特定区域,

const countryName = moment.tz.zone('America/New_York').countries(); // This will return an array from which we can pass the value to locale()
moment.locale(countryName);

You can try like this to get the country name,

const countryName = moment.tz.guess(true);

'guess' will return the browser zone.

To get particular zone other than browser zone,

const countryName = moment.tz.zone('America/New_York').countries(); // This will return an array from which we can pass the value to locale()
moment.locale(countryName);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文