- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我可以为 fromNow()
更改 moment.js 中的时间范围吗,所以小时范围是从 60 秒到 59 分钟,同样对于其他时间范围不是(90 秒 - 45 分钟)。
是否有类似于更改语言的方法:
moment.lang('en', {
relativeTime: {
future: 'Due in %s',
past: '%s ago',
s: 'seconds',
m: 'a minute',
mm: '%d minutes',
h: 'an hour',
hh: '%d hours',
d: 'a day',
dd: '%d days',
M: 'a month',
MM: '%d months',
y: 'a year',
yy: '%d years',
},
});
最佳答案
duration.humanize
具有阈值,用于定义何时将单位视为一分钟、一小时等。例如,默认情况下超过 45 秒被视为一分钟,超过 22 小时被视为一天等等。
要更改这些截止值,请使用 moment.relativeTimeThreshold(unit, limit)
,其中 limit 是 s
、m
、h 之一
, d
, M
.
s
seconds 被认为是一分钟的最少秒数m
minutes 被认为是一个小时的最少分钟数h
hours 一天中最少要考虑的小时数d
days 算作一个月的最少天数M
months 被视为一年的最少月数 // Retrieve existing thresholds
moment.relativeTimeThreshold('s'); // 45
moment.relativeTimeThreshold('m'); // 45
moment.relativeTimeThreshold('h'); // 22
moment.relativeTimeThreshold('d'); // 26
moment.relativeTimeThreshold('M'); // 11
// Set new thresholds
moment.relativeTimeThreshold('s', 40);
moment.relativeTimeThreshold('m', 40);
moment.relativeTimeThreshold('h', 20);
moment.relativeTimeThreshold('d', 25);
moment.relativeTimeThreshold('M', 10);
注意:2.8.1中添加了检索阈值。
关于javascript - Moment.js 更改 fromNow 时间范围,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17473300/
我将日期字符串 2015/05/14-02:55 pm 传递给 moment.js 构造函数,我正在使用 fromNow 将其转换为可读格式。当我在 5 月 16 日运行此命令时,chrome 显示正
当我加载页面时一切正常,但是:为什么 momentjs 不更新时间? 如果我插入一个新帖子,momentjs 不会用一分钟前更新几秒钟前的文本。 这就是我正在做的事情。 我添加了 momentjs:m
我在 Moment 中使用 fromNow,似乎得到了一些奇怪的结果。 var moment = require('moment'); var months = { Jan: '1', Feb
我使用以下代码来计算一个人的年龄: var year = 1964; var month = 1; var day = 20; var age = moment(year + '-' + month
我正在使用https://momentjs.com/ javascript 库,我正在开发一个网络应用程序,它必须使用 .fromNow() 方法比较当前日期和其他日期,但所有结果都会返回 6 个月、
我们正在使用函数fromNow(),但我注意到这个函数无法本地化他的结果。 这些是我的导入:
我使用 moment.js 获取相对时间。例如,它返回“6 小时前”。但我想得到像“6h”这样的短版本。 我阅读了文档:http://momentjs.com/docs/#/customization
我正在使用 moment 来获取事件的时间,并使用 fromNow 功能 moment(value).fromNow(); 不过,这很有效,它告诉我4 天后。问题是,如果少于一天,则会显示4 小时内。
我从服务器收到一个 UTC 日期时间,并试图以可读的形式显示它: moment.utc(utc_date).local().fromNow(); 在我的本地开发环境(Homestead、Laravel
所以我想做的基本上是将用户的时区传递给 fromNow 函数。但是它在控制台中返回此错误 TypeError: moment(...).tz(...) is undefined 这是我的代码 $(do
我在使用 moment.js“fromNow()”函数使用“几秒前”、“一小时前”等文本格式化时间时遇到问题。 它工作得很好,除了它早了几秒钟,这几乎总是不明显,但如果我在数据库中创建一个条目并立即刷
我使用 moment.js v.2.4.0 并使用此脚本来计算已经过去了多少时间 $(".time").append(moment.unix({{ mydb|date('U') }}).fromNow
我是 UI 开发的新手,我必须开发一个页面,其中包含许多带有创建日期的帖子。创建日期相对于当前时间显示,例如“从现在开始 3 小时” 我引用了 this link并且能够成功地做到这一点。但我想每 3
如何正确刷新 moment.from()。我尝试在componentDidMount中设置setInterval(this.renderReminders(), 1000),但是没有用,弹出错误。如何
如何在 Angular 力矩中执行这个 moment().fromNow()? {{ a.Alert.date }}... 如何将 fromNow() 应用到我的变量“a.Alert.date”?
我想使用 momentjs 获取从约会到现在的天数。 我尝试过使用 fromNow() 。该方法返回字符串形式的值。 其单位变化取决于范围的长度。 最佳答案 var m = moment("2014-
我有这个 div 元素,显示自创建以来过去的时间。但是它不会更新,并且始终保持在几秒钟前。看起来像这样 var newMsg= "'+ moment().fromNow()+'"; $("#chat
我可以为 fromNow() 更改 moment.js 中的时间范围吗,所以小时范围是从 60 秒到 59 分钟,同样对于其他时间范围不是(90 秒 - 45 分钟)。 ref: Moment.js
我正在搜索 moment.js docs和 stackoverflow了解一种使用 fromNow() 函数但在数小时内返回所有内容的方法。 我的意思是: moment([2017, 01, 05])
所以我正在使用 moment.js。 我看到您可以使用 moment().fromNow(); 将日期转换为人性化格式; 有没有办法反其道而行之? 例如,我想将这个 --> “2 周前”转换为正常的日
我是一名优秀的程序员,十分优秀!