js 获取时间对象
Posted 银飞仙
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了js 获取时间对象相关的知识,希望对你有一定的参考价值。
1.当前系统时间 var date=new Date();
2.字符串转时间对象 var date=new Date("2018-01-01");
3.获取年份: var year=date.getFullYear();
4.获取月份: var month=date.getMonth()+1;
5.获取天数: var day=date.getDate();
6.获取小时:var hours=date.getHours();
7.获取分钟:var minutes=date.getMinutes();
8.获取秒: var second=date.getSeconds();
获取年龄 age=year-year1;
if(month<month1){
age-=1;
}
以上是关于js 获取时间对象的主要内容,如果未能解决你的问题,请参考以下文章