js简版 TimeUtil 博客分类: jquery javascript
程序员文章站
2024-02-13 17:36:52
...
原地址为:http://bbjava.iteye.com/admin/blogs/1997125。
var TimeUtil = function(){ var date = new Date(); var yyyy = date.getFullYear(); var MM = date.getMonth()+1; var dd = date.getDate(); var HH = date.getHours(); var mm = date.getMinutes(); function getTime(){ return yyyy+"-"+MM+"-"+dd+" "+HH+":00:00"; } function getLastHour(){ date.setHours(date.getHours(), 0, 0, 0); HH = date.getHours(); return yyyy+"-"+MM+"-"+dd+" "+HH+":00:00"; } function getLastDate(){ date.setDate(date.getDate()-1); dd = date.getDate(); return yyyy+"-"+MM+"-"+(dd-1)+" "+HH+":00:00"; } function getLastDay(){ date.setDate(date.getDate()-1); dd = date.getDate(); return yyyy+"-"+MM+"-"+dd; } function getToday(){ return yyyy+"-"+MM+"-"+(dd); } return { getLastHour:function(){ return getLastHour(); }, getTime:function(){ return getTime(); }, getLastDate:function(){ return getLastDate(); }, getLastDay:function(){ return getLastDay(); } }; };