javascript JS Date 时间详解

js获取时间的函数,值得注意的是很多获取之后的值都不是从1开始的,比如说月份获取之后要加1.

<script type="text/javascript">

	var myDate = new Date();
	myDate.getDate()	         //从 Date 对象返回一个月中的某一天 (1 ~ 31)。
	myDate.getDay()	             //从 Date 对象返回一周中的某一天 (0 ~ 6)。
	myDate.getFullYear()	     //从 Date 对象以四位数字返回年份。
	myDate.getHours()	         //返回 Date 对象的小时 (0 ~ 23)。
	myDate.getMilliseconds()	 //返回 Date 对象的毫秒(0 ~ 999)。
	myDate.getMinutes()	         //返回 Date 对象的分钟 (0 ~ 59)。
	myDate.getMonth()	         //从 Date 对象返回月份 (0 ~ 11)。
	myDate.getSeconds()	         //返回 Date 对象的秒数 (0 ~ 59)。
	myDate.getTime()	         //返回 1970 年 1 月 1 日至今的毫秒数。
	myDate.getTimezoneOffset()	 //返回本地时间与格林威治标准时间 (GMT) 的分钟差。
	myDate.getUTCDate()	         //根据世界时从 Date 对象返回月中的一天 (1 ~ 31)。
	myDate.getUTCDay()	         //根据世界时从 Date 对象返回周中的一天 (0 ~ 6)。
	myDate.getUTCFullYear()	     //根据世界时从 Date 对象返回四位数的年份。
	myDate.getUTCHours()	     //根据世界时返回 Date 对象的小时 (0 ~ 23)。
	myDate.getUTCMilliseconds()	 //根据世界时返回 Date 对象的毫秒(0 ~ 999)。
	myDate.getUTCMinutes()	     //根据世界时返回 Date 对象的分钟 (0 ~ 59)。
	myDate.getUTCMonth()	     //根据世界时从 Date 对象返回月份 (0 ~ 11)。
	myDate.getUTCSeconds()	     //根据世界时返回 Date 对象的秒钟 (0 ~ 59)。
	myDate.getYear()	         //已废弃。 请使用 getFullYear() 方法代替。
	myDate.parse()	             //返回1970年1月1日午夜到指定日期(字符串)的毫秒数。
	myDate.setDate()	         //设置 Date 对象中月的某一天 (1 ~ 31)。
	myDate.setFullYear()	     //设置 Date 对象中的年份(四位数字)。
	myDate.setHours()	         //设置 Date 对象中的小时 (0 ~ 23)。
	myDate.setMilliseconds()	 //设置 Date 对象中的毫秒 (0 ~ 999)。
	myDate.setMinutes()	         //设置 Date 对象中的分钟 (0 ~ 59)。
	myDate.setMonth()	         //设置 Date 对象中月份 (0 ~ 11)。
	myDate.setSeconds()	         //设置 Date 对象中的秒钟 (0 ~ 59)。
	myDate.setTime()	         //方法以毫秒设置 Date 对象。
	myDate.setUTCDate()	         //根据世界时设置 Date 对象中月份的一天 (1 ~ 31)。
	myDate.setUTCFullYear()	     //根据世界时设置 Date 对象中的年份(四位数字)。
	myDate.setUTCHours()	     //根据世界时设置 Date 对象中的小时 (0 ~ 23)。
	myDate.setUTCMilliseconds()	 //根据世界时设置 Date 对象中的毫秒 (0 ~ 999)。
	myDate.setUTCMinutes()	     //根据世界时设置 Date 对象中的分钟 (0 ~ 59)。
	myDate.setUTCMonth()	     //根据世界时设置 Date 对象中的月份 (0 ~ 11)。
	myDate.setUTCSeconds()	     //方法用于根据世界时 (UTC) 设置指定时间的秒字段。
	myDate.setYear()	         //已废弃。请使用 setFullYear() 方法代替。
	myDate.toDateString()	     //把 Date 对象的日期部分转换为字符串。
	myDate.toGMTString()	     //已废弃。请使用 toUTCString() 方法代替。
	myDate.toISOString()	     //使用 ISO 标准返回字符串的日期格式。
	myDate.toJSON()	             //以 JSON 数据格式返回日期字符串。
	myDate.toLocaleDateString()	 //根据本地时间格式,把 Date 对象的日期部分转换为字符串。
	myDate.toLocaleTimeString()	 //根据本地时间格式,把 Date 对象的时间部分转换为字符串。
	myDate.toLocaleString()	     //据本地时间格式,把 Date 对象转换为字符串。
	myDate.toString()	         //把 Date 对象转换为字符串。
	myDate.toTimeString()	     //把 Date 对象的时间部分转换为字符串。
	myDate.toUTCString()	     //根据世界时,把 Date 对象转换为字符串。
	myDate.UTC()	             //根据世界时返回 1970 年 1 月 1 日 到指定日期的毫秒数。
	myDate.valueOf()	         //返回 Date 对象的原始值。

</script>
来着: http://www.runoob.com/jsref/jsref-obj-date.html

猜你喜欢

转载自blog.csdn.net/qq_24909089/article/details/80624093
今日推荐