获取一天的开始时间和结束时间
package com.bos.test;
import com.bos.common.file.FileThreadResource;
import org.junit.Test;
import java.io.*;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
* https://www.cnblogs.com/metoy/p/4470418.html
*/
public class MenuTest {
public static void main(String[] args) throws FileNotFoundException, ParseException {
DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
DateFormat format2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = new Date();
String str = format.format(date);
Date date2 = format.parse(str);
System.out.println("开始时间----"+format2.format(date2));
// 一天的毫秒-1
int dayMis = 1000 * 60 * 60 * 24;
// 返回自 1970 年 1 月 1 日 00:00:00 GMT 以来此 Date 对象表示的毫秒数。
// 当天的毫秒
long currentMillisecond = date2.getTime();
// 当天最后一秒
long resultMis = currentMillisecond + (dayMis - 1);
// 得到我须要的时间 当天最后一秒
Date resultDate = new Date(resultMis);
System.out.println("结束时间----"+format2.format(resultDate));
}
}
运行结果: