The method for JAVA to obtain each specified time takes the zero o'clock of the day and the zero o'clock of the previous day as an example

The method for JAVA to obtain each specified time takes the zero o'clock of the day and the zero o'clock of the previous day as an example

Involving the combined use of date format class SimpleDateFormat, calendar class Calendar, and time class Date:

		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置最后用来格式化的格式对象
		Calendar calendar = Calendar.getInstance();//日历对象
        calendar.setTime(new Date());//当天时间赋给日历对象
        calendar.set(Calendar.HOUR_OF_DAY, 0);//设置对象日历格式
        calendar.set(Calendar.MINUTE, 0);//设置为当天零点
        calendar.set(Calendar.SECOND, 0);
        Date nowday = calendar.getTime();//再返回时间对象
        calendar.add(Calendar.DAY_OF_MONTH, -1);//设置为上一条
        Date startDate = calendar.getTime();//返回另一个时间对象
        //宝信的框架,用中间件inInfo传输数据,不必在意
		inInfo.setCell("inqu_status", 0, "PRODUCE_TIME", sdf.format(startDate));
		inInfo.setCell("inqu_status", 0, "PRODUCE_TIMEEnd", sdf.format(nowday));

2.24 update supplement:
see a news on the Internet, take a Insert picture description here
warning hahahahaha

Guess you like

Origin blog.csdn.net/Beatingworldline/article/details/113858431