package com.test;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Random;
import java.util.Scanner;
import java.util.UUID;
import java.util.concurrent.ThreadLocalRandom;
public class M1001{
public static void main(String[] args) throws ParseException {
// 需求:查询最近一周。。。的信息,如何表示最近这一周
Date current = new Date();
Date endTime = null;
Calendar c = Calendar.getInstance();
c.setTime(current);
//把日增加一天,时分秒设置为0
c.set(Calendar.DAY_OF_MONTH, 0);
c.set(Calendar.HOUR_OF_DAY,0);
c.set(Calendar.SECOND,0);
endTime = c.getTime();
c.add(Calendar.DAY_OF_MONTH, -7);
Date beginTime = c.getTime();
System.out.println("开始时间:"+beginTime.toLocaleString());
System.out.println("结束时间:"+endTime.toLocaleString());
}
}
Calendar如何计算最近一周的算法
最新推荐文章于 2024-04-19 11:37:39 发布