JS setMilliseconds()设置日期对象毫秒数

setMilliseconds()方法

JavaScript的日期Date对象调用setMilliseconds()方法,可以根据参数指定的毫秒数来设置或改变该调用对象中的毫秒。


setMilliseconds()语法

这是一个方法,需要通过Date对象来调用:

dateObj.setMilliseconds( millisecondsValue )

参数

参数描述
millisecondsValue以Number类型的数值传入,指定毫秒数

返回值

无,但可以修改Date对象。


setMilliseconds()方法实例代码,及在线编辑器

如下实例,通过setMulliseconds分别设置了666毫秒和2000毫秒,可以观察now_date值的变化:

<script>
  var now_date = new Date()
  alert(now_date)
  now_date.setMilliseconds(666)
  alert(now_date)
  now_date.setMilliseconds(2000)
  alert(now_date)
</script>

全栈前端 / JavaScript语法 :





















Copyright © 2022-2024 笨鸟工具 x1y1z1.com All Rights Reserved.