public static void main(String[] args) throws Exception
{
Date dateNow=new Date();
Date dateBefore=new Date();
Calendar cal=Calendar.getInstance();
cal.setTime(dateNow);
cal.add(Calendar.DAY_OF_MONTH, -1);
dateBefore=cal.getTime();
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
String time1=sdf.format(dateBefore)+" 00:00:00";
Date d1=sdf.parse(time1);
long startTime=d1.getTime()/1000;
long endTime=startTime+86399;
System.out.println("startTime="+startTime);
System.out.println("endTime="+endTime);
}
控制台打印:
startTime=1497283200
endTime=1497369599
java获取当前时间的前一天时间
最新推荐文章于 2024-09-14 15:42:17 发布