如果要以较短的方式格式化时间,可以使用 @researchgate 的 moment-shortformat 插件。
它基于和类似于 moment.twitter 插件,但输出不同。
moment().subtract(5, 'hours').short();
// 5h ago
moment().add(5, 'hours').short();
// in 5h
您还可以禁用相对时间模板的使用:
moment().subtract(1, 'hour').short(false);
// 1h
如果该日期在将来或过去过长,它将会显示为:
moment().subtract(500, 'days').short();
// 5 Mar, 1970
If you want to format times in a short way, you can use the moment-shortformat plugin by @researchgate.
It is based on and similar to the moment.twitter plugin but has a different output.
moment().subtract(5, 'hours').short();
// 5h ago
moment().add(5, 'hours').short();
// in 5h
You can also disable the use of the relative time templates
moment().subtract(1, 'hour').short(false);
// 1h
If the date is too far in the future or the past it will display like that
moment().subtract(500, 'days').short();
// 5 Mar, 1970