Moment.js的parseZone()方法

moment.parseZone() 函数方法解析提供的字符串,并将生成的时刻保留在固定的时区中。此外,此方法分析字符串,但将生成的 Moment 对象保留在固定偏移量时区中,并在字符串中提供偏移量

  • 语法
    moment.parseZone()
    moment.parseZone(String)
  • 参数
    具有提供的偏移量的 固定偏移时区
  • 返回类型
    此函数将 Moment 对象返回到本地或 UTC 时间

这在正常的 Node.js 程序中不起作用,因为它需要一个外部js库来全局安装或在项目目录中安装

npm install moment

获取当前解析时区

const moment = require('moment');
var a = moment().parseZone();
console.log("Current parse Timezone: ",a)

输出

Current parse Timezone:  Moment<2022-10-13T12:21:25+00:00>

解析时区

const moment = require('moment');
var a = moment("2022-01-01T00:00:00-16:00").utcOffset("2022-01-01T00:00:00-16:00");
var b = moment.parseZone("2022-01-01T00:00:00-16:00");
console.log("Current parse Timezone: ",a)
console.log("Current parse Timezone: ",b)

输出

Current parse Timezone:  Moment<2022-01-01T00:00:00-16:00>
Current parse Timezone:  Moment<2022-01-01T00:00:00-16:00>
© 版权声明
THE END
喜欢就支持一下吧
点赞0打赏 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容