JavaScript中的Date.setTime()函数
Date对象是JavaScript语言中内置的数据类型。日期对象使用新的Date()创建,如下所示。
创建Date对象后,可以使用多种方法对其进行操作。大多数方法仅允许您使用本地时间或UTC(通用或GMT)时间来获取和设置对象的年,月,日,时,分,秒和毫秒字段。
使用Date对象的setTime()函数可以设置当前日期的时间。
语法
它的语法如下
dateObj.setTime();
示例
<html>
<head>
<title>JavaScript Example</title>
</head>
<body>
<script type="text/javascript">
var dateObj1 = new Date('september 26, 89 5:4:25:96');
var dateObj2 = new Date('November 1, 79 6:1:00:00');
document.write("Current date: "+dateObj2.toUTCString());
document.write("<br>");
dateObj2.setTime(dateObj1.getTime());
document.write("Modified date: "+dateObj2.toUTCString());
</script>
</body>
</html>输出结果
Current date: Thu, 01 Nov 1979 00:31:00 GMT Modified date: Mon, 25 Sep 1989 23:34:25 GMT
热门推荐
1 训练狗狗基础
2 怎么训练狗狗笑
3 怎么训练狗狗卧下
4 上海狗狗训练基地
5 训练狗狗排便
6 狗狗基础训练
8 如何训练狗狗装死
9 狗狗站姿训练
10 狗狗训练用品
11 训练狗狗吧
12 狗狗要怎么训练
13 怎么训练狗狗玩球
14 训练狗狗唤回
15 狗狗训练躺下
16 狗狗训练指令
17 狗狗的训练技巧
18 狗狗不好训练