数据库mysql 今日、昨日或n天前0点时间戳 java本周一时间戳 JavaScript上周一到周日

昨天: UNIX_TIMESTAMP(CAST(SYSDATE()AS DATE) - INTERVAL 1 DAY)

今天:

UNIX_TIMESTAMP(CURDATE())

n天前: UNIX_TIMESTAMP(CAST(SYSDATE()AS DATE) - INTERVAL  n  DAY)

 

 

本月第一天:

UNIX_TIMESTAMP(DATE_ADD(CURDATE(), INTERVAL - DAY(CURDATE()) + 1 DAY))

指定时间戳的月份: EXTRACT(MONTH FROM FROM_UNIXTIME(指定时间戳))

 

//获得本周一0点时间
public static int getTimesWeekmorning(){
    Calendar cal = Calendar.getInstance();
    cal.set(cal.get(Calendar.YEAR),cal.get(Calendar.MONDAY), cal.get(Calendar.DAY_OF_MONTH), 0, 0,0);
    cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
    return (int) (cal.getTimeInMillis()/1000);
}

 

weeklyTime:function(){

let dataValue = new Date();

let year = dataValue.getFullYear();

let month = dataValue.getMonth() + 1;

let day = dataValue.getDate();

let thisWeekStart; //本周周一的时间

if (dataValue.getDay() == 0) { //周天的情况;

thisWeekStart = (new Date(year + '/' + month + '/' + day)).getTime() - ((dataValue.getDay()) + 6) * 86400000;

} else {

thisWeekStart = (new Date(year + '/' + month + '/' + day)).getTime() - ((dataValue.getDay()) - 1) * 86400000;

}

//获得上周时间

let arr = [];

arr[0] = (thisWeekStart - 7 * 86400000) / 1000;//上周周一的时间

arr[1] = (thisWeekStart - 1000) / 1000;//上周周日的时间

return arr

},

你可能感兴趣的:(java,JavaScript,mysql)