- Date()
Date 对象的方法
方法 | 描述 |
---|---|
Date() | 返回当日的日期和时间 |
getDate() | 从 Date 对象返回一个月中的某一天 (1 ~ 31) |
getDay() | 从 Date 对象返回一周中的某一天 (0 ~ 6) |
getMonth() | 从 Date 对象返回月份 (0 ~ 11) 注意:写代码时应该+1; |
getFullYear() | 从 Date 对象以四位数字返回年份 |
getHours() | 返回 Date 对象的小时 (0 ~ 23) |
getMinutes() | 返回 Date 对象的分钟 (0 ~ 59) |
getSeconds() | 返回 Date 对象的秒数 (0 ~ 59)) |
getMilliseconds() | 返回 Date 对象的毫秒(0 ~ 999) |
getTime() | 返回 1970 年 1 月 1 日至今的毫秒数 |
toLocaleString() | 根据本地时间格式,把 Date 对象转换为字符串。 |
例1:
<script type="text/javascript">
<!--
var d = new Date() ;
document.write(d) ;
document.write("<br>") ;
document.write(d.toLocaleString()) ;
document.write("<br>") ;
document.write(d.getFullYear()+"-"+(d.getMonth()+1)+"-"+d.getDate()+
" "+d.getHours()+":"+d.getMinutes()+":"+d.getSeconds()) ;
//-->
</script>
显示结果为:
Sat Jul 09 2016 21:25:49 GMT+0800
2016/7/9 下午9:25:49
2016-7-9 21:25:49