我有一个数字代表午夜后的毫秒数。
我希望使用<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
<head>
<script>
i=1;
$(document).ready(function(){
$("button").click(function(){
if(i==1){
document.getElementById("tf1").setAttribute("fill", "transparent");
document.getElementById("tf2") .setAttribute("fill", "yellow");
i=2;
}else if (i==2){
document.getElementById("tf2").setAttribute("fill", "transparent");
document.getElementById("tf3") .setAttribute("fill", "green");
i=3;
} else if(i==3) {
document.getElementById("tf3").setAttribute("fill", "transparent");
document.getElementById("tf1").setAttribute("fill", "red") ;
i=1;
}
});
});
</script>
之类的数字并获取Time对象(在此示例中为3600000
)。
MomentJS中是否有一种干净的方法可以在不编写我自己的自定义代码的情况下执行此操作?
答案 0 :(得分:1)
Moment没有Time
个对象,但你当然可以生成一个字符串。
moment.utc(3600000).format('h:mm a') // "1:00 am"
请注意,在此特定情况下,使用moment.utc
优先于moment
,以避免与夏令时相关的问题。