JavaScript中日期函数的相关操作知识
时间对象是一个我们经常要用到的对象,无论是做时间输出、时间判断等操作时都与这个对象离不开。除开JavaScript中的时间对象外,在VbScript中也有许多的时间对象,而且非常好用。狼蚁网站SEO优化还是按照我们的流程来进行讲解JavaScript中日期函数。
new Date()
new Date(milliseconds)
new Date(datestring)
new Date(year, month)
new Date(year, month, day)
new Date(year, month, day, hours)
new Date(year, month, day, hours, minutes)
new Date(year, month, day, hours, minutes, seconds)
new Date(year, month, day, hours, minutes, seconds, microseconds)
狼蚁网站SEO优化对
1.new Date(),没有参数的时候,创建的是当前时间日期对象。
2.new Date(milliseconds),当参数为数字的时候,那么这个参数就是时间戳,被视为毫秒,创建一个距离1970年1月一日指定毫秒的时间日期对象。
3.new Date(datestring),此参数是一个字符串,并且此字符串一定能够使用Date.parse()转换。
4.以下六个构造函数是精确定义:
1).year,是一个整数,如果是0-99,那么在此基础上加1900,其他的都原样返回。
2).month,是一个整数,范围是0-11。
3).day,是一个整数,范围是1-31。
4).hours,是一个整数,范围是0-23。
5).minutes,是一个整数,范围是0-59。
6).seconds,是一个整数,范围是0-59。
7).microseconds 是一个整数,范围是0-9999。
<html> <head> <title>时间戳转化为年月日时分秒</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> </head> <body> </body> </html> <script> window.onload=function(){ var now=new Date();//当前系统时间 var shijianchuo = now.getTime();//获取当前时间戳 alert("时间戳:"+shijianchuo); var nowdate = new Date(shijianchuo);//将时间戳转化为日期对象 var nowtime=nowdate.Format("yyyy-MM-dd hh:mm:ss");//格式化当前系统时间,相当于将时间戳转化为年月日时分秒了 alert("当前时间:"+nowtime); } /* 日期格式化: 对Date的扩展,将 Date 转化为指定格式的String 年(y)可以用1-4个占位符,季度(q)可以用1-2个占位符. 月(M)、日(d)、小时(h)、分(m)、秒(s)可以用1-2个占位符. 毫秒(S)只能用1个占位符(是1-3位的数字) 例子: (new Date()).Format("yyyy-MM-dd hh:mm:ss.S") (new Date()).Format("yyyy-MM-dd hh:mm:ss.S毫秒 第qq季度") */ Date.prototype.Format = function (fmt) { var o = { "M+": this.getMonth() + 1, //月 "d+": this.getDate(), //日 "h+": this.getHours(), //时 "m+": this.getMinutes(), //分 "s+": this.getSeconds(), //秒 "q+": Math.floor((this.getMonth() + 3) / 3), //季度 "S": this.getMilliseconds() //毫秒 }; if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length)); for (var k in o) if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length))); return fmt; } </script>
编程语言
- 机械手焊接机器人编程 机械手焊接设备编程
- vb数据库编程实例,vb做数据库
- tiobe世界编程语言排行榜,全球编程语言排行
- 成都java编程培训 成都it编程培训中心
- 编程基础培训,编程基础知识培训
- flash游戏编程基础教程,flash游戏开发教程
- 不会英语能学编程吗 不会英语可以学程序员吗
- 爱心代码编程C语言 爱心代码编程c语言公式
- c语言编程学习入门 c语言编程快速入门
- 西门子plc编程培训 西门子plc编程培训班
- 哪里可以学编程 台州哪里可以学编程
- 少儿编程哪个好 少儿编程哪个品牌好
- 编程是什么意思,图形编程是什么意思
- c语言编程软件下载,c语言编程软件在哪下载
- java编程软件下载,java编程下载手机版
- ug编程培训学校,ug编程培训教程