js获取时间
来源:互联网 发布:淘宝企业店铺运营 编辑:程序博客网 时间:2024/06/05 20:40
<script type="text/javascript">
var Dates = {};
Dates.box = function(){
var n,d,nowdate,otherdate,style;
return{
date:function(){
//获取当日年、当月、当日时间
d = new Date();
nowdate = {ny:d.getFullYear(),nm:d.getMonth()+1,nd:d.getDate()};
return this.dateGroup(nowdate,style);
},
sdate:function(){
//获取第N天的日期
d.setTime(d.getTime()+24*(n-1)*3600*1000);
otherdate = {ny:d.getFullYear(),nm:d.getMonth()+1,nd:d.getDate()};
return this.dateGroup(otherdate,style);
},
dateGroup:function(y,style){
//日期拼合
switch(style){
case 1:
ndate = y.ny+'-'+y.nm+'-'+y.nd;
break;
case 2:
ndate = y.nm+'-'+y.nd+'-'+y.ny;
break;
}
return ndate
}
,
showDate:function(a,b){
n = a;
style = b;
//展示时间
nowdate = this.date();
otherdate = this.sdate();
}
}
}();
Dates.box.showDate(5,1);
</script>
写这个日期时间,学到 d.setTime、d.getTime()
d.getTime()是获取当前天数的时间,单位是毫米(所以计算一天的方法是24*3600*1000)一天有24小时,一小时3600秒,因为这是以毫秒记所以乘以1000即为1天的毫秒时。而setTime是设置当前时间的。
d.setTime(d.getTime()+24*(n-1)*3600*1000); //n-1其实就是算几天的,比如2-1到2-5,这五天,那么n就是5。
- Js获取 时间 日期
- JS获取当前时间
- JS 获取服务器时间
- js获取当前时间
- js获取时间
- js 获取当前时间
- Js获取当前时间
- js 时刻获取时间
- js获取系统时间
- js获取时间
- js 获取当前时间
- js获取时间
- js获取时间
- js 获取系统时间
- js获取当前时间
- js获取时间
- js获取时间
- js获取服务器时间
- ADO.NET中不常用的功能
- ubuntu 10.04 下的crontab学习
- 使用JAVA开发系统托盘程序
- SCWS分词学习之一
- C++简单笔试题
- js获取时间
- 常用maven命令
- Maven编译时跳过Test
- Docbook学习
- sip学习的网页博客
- Linux性能指标
- connect: network is unreachable
- arm 的pc和lr寄存器
- WPF之自定义窗体