
需要准备的材料分别有:电脑、html编辑器、浏览器。
1、首先,打开html编辑器,新建html文件,例如:indexhtml。
2、在indexhtml中的<script>标签,输入js代码:
var a = new Date();documentbodyinnerHTML
= '时:' + agetHours() + '<br/>分:' + agetMinutes() + '<br/>秒:' + agetSeconds();
3、浏览器运行indexhtml页面,此时当前时间的时分秒都被js获取并打印了出来。
javascript 自带有个对象(构造函数),Date()下面是代码:
var myDate = new Date(); //实例一个时间对象;
myDategetFullYear(); //获取系统的年;
myDategetMonth()+1; //获取系统月份,由于月份是从0开始计算,所以要加1
myDategetDate(); // 获取系统日,
myDategetHours(); //获取系统时,
myDategetMinutes(); //分
myDategetSeconds(); //秒
var recu = function(sleep){
setTimeout(function(){
var now = new Date;
nowsetDate(nowgetDate() - 1);
var x = "" + nowgetFullYear() + (nowgetMonth() + 1) + nowgetDate();
x = xsubstr(2);
documentwrite("");
documentwrite(x);
documentclose();
recu(72460601000);
}, sleep);
}
recu(0);
<script type="text/javascript">
function myfunction() {
var old = new Date('1980-01-01 00:00:00');
var n = new Date();
var s = n - old;
return Mathfloor(s / (24 3600 1000));
}
alert('1980-01-01 00:00:00 距今已过去:' + myfunction() + '天');
</script>
以上就是关于js 怎么获取年月日时分秒中的时分秒全部的内容,包括:js 怎么获取年月日时分秒中的时分秒、javascript 分别读取时间中的年、月、日、时、分、秒的方法、js获取当前年月日前一天,7天后更新,例如20141005显示为141004七天之后20141012显示为141011,依次类推等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)