- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想检查当前 utc 时间距事件日期是否小于 1 天。我传入的事件日期减去一天。本质上,我想看看当前的 utc 时间是否距事件日期不到一天,但此查询返回 false,而不是 true!!
例如。传入 utc 时间和 1 天以内的时间,然后检查是否距当前 utc 时间不到 1 天
if (moment().utc().isSameOrAfter(moment("4/13/2018 7:30:00 PM").add(-1, 'days').utc())) {
// returns false but should be true because it's less then one day from 4/13/2018 7:30PM
}
最佳答案
问题在于您解析输入的方式。由于 "4/13/2018 7:30:00 PM"
既不符合 ISO 8601 也不符合 RFC 2822 已知格式,因此您必须使用 moment(String, String)
而不是moment(String)
:
When creating a moment from a string, we first check if the string matches known ISO 8601formats, we then check if the string matches the RFC 2822 Date time format before dropping to the fall back of new Date(string) if a known format is not found.
For consistent results parsing anything other than ISO 8601 strings, you should use String + Format.
根据您的情况,您可以使用:
moment("4/13/2018 7:30:00 PM", "M/D/YYYY h:mm:ss A")
而不是
moment("4/13/2018 7:30:00 PM")
关于javascript - 将当前时间与距离不到 1 天的事件进行比较时,Moment js "isSameOrAfter()"为 false,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49806094/
System.Math.MomentSkewKurtosis 声明为 procedure MomentSkewKurtosis(const Data: array of Double; var M1,
我尝试在应用程序中使用 moment.js 和 moment-timezone-with-data.js 来显示任何时区的日期。 我已将这两个 js 文件的 CDN 包含在我的 index.html
我对 Moment 函数的工作原理有点困惑(例如 startOf()、weekday() 等)。 我的问题是:如何从预定义的日期获取一周的开始? 考虑 9/21/16 上的这两个调用: moment(
阅读react-datepicker doc's后我尝试按照文档的说明更改日期选择器语言: Globally by calling moment.locale(lang) Picker-specifi
我有一个服务器生成的位置列表,采用国家/城市格式,即 Beijing London 我想使用 JS/Jquery 和 Moment Timezone 来执行此操作: 从每个项目中提取 data-tim
我有一个时刻对象和一个单独的时间字符串,如下所示: var selectedDay = moment(); var time = '6 PM'; 我想将两者结合起来,我无法从文档中弄清楚,就像这样。
我有一个时刻对象,我正在尝试添加几天。但是,它返回的结果是相同的 moment 对象。 但是,如果我只是尝试在当前日期执行此操作,则效果很好。 另外,请注意,我总是收到一个需要添加天数的时刻对象。 代
我有一个名为 date 的时刻对象: ( Tue Apr 09 2019 00:00:00 ...) 我想在最后一刻将其替换为同一天,如下所示: (Tue Apr 09 2019 23:59:59 .
目前我有一个输入字段,允许您通过输入两位数字来选择一个小时。例如,您可以选择 12 表示 12 小时。 有没有办法使用 MomentJS 将该数字转换为毫秒? 目前我必须做以下数学运算。我在 Mome
moment().format() 根据 moment().isValid() 创建无效日期 示例如下: > moment.version "2.14.1" > moment.locale() "fr
我正在使用 moment.js,但在测试 moment.js 库时,我继续收到错误。 var back30Days=moment().subtract(30, 'days').format("dddd
在使用 moment 构建 angular 8 项目时,我遇到了以下错误消息: ng build @myproject/common Error: Cannot call a namespace ('
我安装了 moment.js 库并准备稍微玩弄它,当我收到此错误时。我尝试了很多不同的东西,但没有任何效果。有任何想法吗? 我有一个文件夹,我已经将 moment.js 安装到(npm install
我有一个时间戳的初始值(在 User-1 的时区中创建),我正在从 firebase 的 firestore 中检索。其格式为 Unix 纪元的 UTC 秒数。 我的目标是获取初始时间戳值,并将其转换
有一个从元素的 innerText 设置的 startTime。然后使用 moment(startTime) 将该字符串转换为 Moment.js 对象。然后如何将其转换为以分钟为单位的数字值? Ja
我使用 moment.js 创建了一个 js 脚本,我想通过 cron 作业复制它。因此,它将使用 PHP。 所以,我搜索了 moment.js 的等价物,我找到了这个 https://github.
我得到一个文本值,它的格式如下:“9/19/2018 10:00 AM”。您将如何使用 moment.js 或仅使用 javascript 将其转换为纪元时间戳? 示例: console.log(mo
$> moment.version '2.18.1' $> moment('Mon, 02 Jan 2017 06:00:00 -0800').format() '2017-01-02T01:00:0
我有一个jsfiddle here 。 它是空白的,因为我想做的事情不起作用...... 我已经调用了适当的外部脚本。 我正在尝试将这个令人难以置信的库实现到我的网站中,但我不确定我做错了什么。 最终
我有 moment 对象,我想将其转换为格式为 dd.mm.yy 的字符串。使用 moment.js 执行此操作的最佳方法是什么? 我尝试了toString函数,但它返回的日期格式为Wed Mar 2
我是一名优秀的程序员,十分优秀!