字串變日期
// value:'2014/08/06'
function becomeRealDate(split_realdata1){
var checkdate = split_realdata1.split('\/');
var year = parseInt(checkdate[0]);
var month = parseInt(checkdate[1]);
var day = parseInt(checkdate[2]);
var newdate = new Date();
newdate.setFullYear(year);
newdate.setMonth(month-1);
newdate.setDate(day);
return newdate;
}
藉由實際日期值(Date)增加5天,獲得新日期值
//value: new Date(), 5
function addDate(newdate , addday){
var expectdate = new Date(newdate);
expectdate.setDate(newdate.getDate()+addday);
return expectdate;
}
兩個日期的比較,如果值大於0 ,則date2較後期
//value: new Date , new Date
function comparetime(date1 , date2){
start = Math.floor( date1.getTime() / (3600*24*1000)); //days as integer from..
end = Math.floor( date2.getTime() / (3600*24*1000)); //days as integer from..
daysDiff = end - start; // exact dates
return daysDiff;
}
沒有留言:
張貼留言