JS有关日期的基本操作

来源:互联网 发布:青岛乐智网络 编辑:程序博客网 时间:2024/06/07 19:25

问:用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();