简体   繁体   English

如何使用moment.js更正分钟值?

[英]How to correct minutes value with moment.js?

I need to some correct Date minute value like the following: 我需要一些正确的日期分钟值,如下所示:

var d = new Date();
d.setMinutes(d.getMinutes() < 30 ? 0 : 30);

So if minutes less than "30" that it should be "0" and if greater than "30" that "30"; 因此,如果分钟数小于“ 30”,则应为“ 0”,如果分钟数大于“ 30”,则应为“ 30”;

Is it possible by using moment.js ? 有可能通过使用moment.js吗?

Yes, you should be able to do the same thing using .minute(value) : 是的,您应该可以使用.minute(value)做同样的事情:

var m = moment(new Date());
m.minute(m.minute() < 30 ? 0 : 30);

Here is the section of the docs. 这是文档的部分

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM