Moment js - 在不考虑时区的情况下获取日期 [英] Moment js - get date without considering time zone

查看:43
本文介绍了Moment js - 在不考虑时区的情况下获取日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我确实阅读了不同的 StackOverflow 帖子,他们建议从那一刻起使用 .utc 但它不起作用

I did read different StackOverflow posts and they suggested to use .utc from moment but it doesn't work

注意:我在 PST 区域

const start = '2018-06-10T21:00:00-04:00';
const end = '2018-06-10T23:00:00-04:00';
const noconversion = moment.utc(start).format('MM/DD/YYYY');
const converted = moment(end).format('MM/DD/YYYY');

当前输出:

无转换 - 2018-06-11

noconversion - 2018-06-11

已转换 - 2018-06-11

converted - 2018-06-11

预期输出:06/10/2018 只是从提供的日期中获取日期

Output expected: 06/10/2018 just fetch date from date provided

CODEPEN 链接

推荐答案

您是否尝试过 parseZone?

Have you tried parseZone?

moment.parseZone(end).format('MM/DD/YYYY');

这应该会应用您的 UTC 偏移量.如果您想保存它,您还可以计算 UTC 偏移量:

That should keep your UTC offset applied. You can then also calculate the UTC offset, if you wanted to save that:

moment.parseZone(end).format('MM/DD/YYYY').utcOffset();

这篇关于Moment js - 在不考虑时区的情况下获取日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆