真实的国产乱ⅩXXX66竹夫人,五月香六月婷婷激情综合,亚洲日本VA一区二区三区,亚洲精品一区二区三区麻豆

成都創(chuàng)新互聯(lián)網(wǎng)站制作重慶分公司

java上周一至周日代碼 java 星期

java 如何獲取 上周一日期,上周末日期,本周一日期。

獲取本周一

創(chuàng)新互聯(lián)公司主要從事成都網(wǎng)站制作、網(wǎng)站設(shè)計、網(wǎng)頁設(shè)計、企業(yè)做網(wǎng)站、公司建網(wǎng)站等業(yè)務(wù)。立足成都服務(wù)霍爾果斯,十多年網(wǎng)站建設(shè)經(jīng)驗,價格優(yōu)惠、服務(wù)專業(yè),歡迎來電咨詢建站服務(wù):028-86922220

public?static?Date?getNowWeekMonday(Date?date)?{????

Calendar?cal?=?Calendar.getInstance();????

cal.setTime(date);????

cal.add(Calendar.DAY_OF_MONTH,?-1);?//解決周日會出現(xiàn)?并到下一周的情況????

cal.set(Calendar.DAY_OF_WEEK,?Calendar.MONDAY);????

303????????????return?cal.getTime();????

}

獲取上周一

public?static?Date?getLastWeekMonday(Date?date)?{????

Date?a?=?DateUtils.addDays(date,?-1);????

Calendar?cal?=?Calendar.getInstance();????

cal.setTime(a);????

cal.add(Calendar.WEEK_OF_YEAR,?-1);//?一周????

cal.set(Calendar.DAY_OF_WEEK,?Calendar.MONDAY);????

return?cal.getTime();????

}

獲取上周日

public?static?Date??getLastWeekSunday(Date?date)?{????

Date?a?=?DateUtils.addDays(date,?-1);????

Calendar?cal?=?Calendar.getInstance();????

cal.setTime(a);????

cal.set(Calendar.DAY_OF_WEEK,?1);????

return?cal.getTime();????

}

代碼里面有用到?lapache.common-ang包 你需要下載下 就可以使用

java獲取某個時間的上周一和周日

mport java.text.SimpleDateFormat;

import java.util.Calendar;

public class Test{

public static void main(String args[]){

Calendar cal = Calendar.getInstance();

//n為推遲的周數(shù),1本周,-1向前推遲一周,2下周,依次類推

int n = 2;

String monday;

cal.add(Calendar.DATE, n*7);

//想周幾,這里就傳幾Calendar.MONDAY(TUESDAY...)

cal.set(Calendar.DAY_OF_WEEK,Calendar.MONDAY);

monday = new SimpleDateFormat("yyyy-MM-dd").format(cal.getTime());

System.out.println(monday);

}

}

java如何得到上周一和上周日的日期

/**

* 獲取上周五時間

*/

public Date lastFirday() {

//作用防止周日得到本周日期

Calendar calendar = Calendar.getInstance();

while (calendar.get(Calendar.DAY_OF_WEEK) != Calendar.MONDAY) {

calendar.add(Calendar.DAY_OF_WEEK, -1);

}

int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK) - 1;

int offset = 7 - dayOfWeek;

calendar.add(Calendar.DATE, offset - 9);

return DateTimeUtil.getFirstDayOfWeek(calendar.getTime(), 6);//這是從上周日開始數(shù)的到本周五為6

}

/**

* 獲取上周一時間

*/

public Date lastMonday() {

Calendar calendar = Calendar.getInstance();

while (calendar.get(Calendar.DAY_OF_WEEK) != Calendar.MONDAY) {

calendar.add(Calendar.DAY_OF_WEEK, -1);

}

int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK) - 1;

int offset = 1 - dayOfWeek;

calendar.add(Calendar.DATE, offset - 7);

return DateTimeUtil.getFirstDayOfWeek(calendar.getTime(), 2);

}


文章標(biāo)題:java上周一至周日代碼 java 星期
文章URL:http://weahome.cn/article/dopsded.html

其他資訊

在線咨詢

微信咨詢

電話咨詢

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部