package com.ishang.test;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
public class Test {
/**
* 得到本周周一
*
* @return yyyy-MM-dd
*/
public static String getMondayOfThisWeek() {
Calendar c = Calendar.getInstance();
int dayofweek = c.get(Calendar.DAY_OF_WEEK) - 1;
if (dayofweek == 0)
dayofweek = 7;
c.add(Calendar.DATE, -dayofweek + 1);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
System.out.println("本周第一天="+sdf.format(c.getTime()));
return sdf.format(c.getTime());
}
/**
*得到本周周日
* @return yyyy-MM-dd
*/
public static String getSundayOfThisWeek() {
Calendar c = Calendar.getInstance();
int dayofweek = c.get(Calendar.DAY_OF_WEEK) - 1;
if (dayofweek == 0)
dayofweek = 7;
c.add(Calendar.DATE, -dayofweek + 7);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
System.out.println(sdf.format(c.getTime()));
return sdf.format(c.getTime());
}
/**
* 得到本月最后一天
*
* @return
*/
public static String getLastDateOfMonth()
{
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
Date dt = new Date();
if (dt == null)
return null;
Calendar cal = Calendar.getInstance();
cal.setTime(dt);
int days = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
cal.set(Calendar.DAY_OF_MONTH, days);
String result = format.format(cal.getTime());
System.out.println("一个月最后一天" + result);
return result;
}
/**
* 得到本月第一天
*
* @return
*/
public static String getFristDateOfMonth()
{
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
Date dt = new Date();
if (dt == null)
return null;
Calendar cal = Calendar.getInstance();
cal.setTime(dt);
int days = cal.getActualMinimum(Calendar.DAY_OF_MONTH);
cal.set(Calendar.DAY_OF_MONTH, days);
String result = format.format(cal.getTime());
System.out.println("一个月第一天" + result);
return result;
}
public static void main(String[] args) {
getMondayOfThisWeek();
getSundayOfThisWeek();
getFristDateOfMonth();
getLastDateOfMonth();
}
}
最近下载更多
情义^DASK LV2
2021年12月11日
262000000 LV1
2021年2月17日
kong.yee LV40
2020年6月26日
低调人 LV38
2019年8月3日
sky19961212 LV18
2018年12月26日
长大的小孩 LV2
2018年4月28日
liulei88 LV14
2018年2月22日
sunboris514 LV8
2018年1月4日
Anonymous_love LV4
2017年9月17日
scpcyzxb LV16
2017年8月14日
最近浏览更多
syhsyhzxhzxh LV3
2023年11月17日
heqian LV17
2022年12月5日
微信网友_6040315240812544 LV8
2022年10月20日
情义^DASK LV2
2021年12月11日
root123456qwe LV1
2021年9月3日
262000000 LV1
2021年2月17日
kong.yee LV40
2020年6月26日
LikL9420 LV12
2020年4月28日
玛瑙菲尔
2020年3月3日
暂无贡献等级
peng99 LV1
2019年12月25日

