JS有关日期的基本操作

版权声明:技术成长的艰难岁月,沧桑的是容颜,不变的是真心,虽然我不是特别喜欢Code ! https://blog.csdn.net/qq_25037705/article/details/76520155

问:用JS如何获取系统时间并拆分?对指定的时间如何拆分?
答:如下所示:
//获取当前日期 并 拆分

var thisTime=new Date();

var thisTimeYear=thisTime.getFullYear();//年
var thisTimeMonth=thisTime.getMonth()+1;//月
var thisTimeWeek=thisTime.getDay();//星期
var thisTimeDay=thisTime.getDate();//日
var thisTimeHour=thisTime.getHours();//时
var thisTimeMinute=thisTime.getMinutes();//分
var thisTimeSecond=thisTime.getSeconds();//秒

//对指定的日期进行拆分

var date;
var targetYear=(new Date(date)).getFullYear();
var targetMonth=(new Date(date)).getMonth()+1;
var targetDay=(new Date(date)).getDay();
var targetDate=(new Date(date)).getDate();
var targetHours=(new Date(date)).getHours();
var targetMinutes=(new Date(date)).getMinutes();
var targetSeconds=(new Date(date)).getSeconds();

猜你喜欢

转载自blog.csdn.net/qq_25037705/article/details/76520155