Java based on the time of day to obtain the time between the first 7 days and the number of days after the query time
Package Com.kugou.schedu.service;import Java.text.parseexception;import Java.text.simpledateformat;import Java.util.calendar;import Java.util.date;import Java.util.gregoriancalendar;import Org.springframework.beans.factory.annotation.autowired;import Org.springframework.stereotype.component;import Com.kugou.schedu.dao.SongHotDao; @Componentpublic class Songhotservice {public static void main (string[] args) throws parseexception {Getdaybetween (7, 7);} /** * Get start time to end time based on current time * * @param day * Get time between days * @return start time and end time */public static date[] Getdaybet Ween (Integer Day) {//Today full-time Date Startdt = new Date (); SimpleDateFormat SDF = new SimpleDateFormat ("Yyyy-mm-dd"); String s = Sdf.format (Startdt.gettime ()); try {Startdt = Sdf.parse (s);} catch (ParseException e) {e.printstacktrace ();} Calendar calendar = new GregorianCalendar (), Calendar.settime (New Date (Startdt.gettime ()-1)), Calendar.add (calendar. DATE, day);//Long ENDDT = 604800L + startdt.gettime (); System.out.println (StartDT); System.out.println (Calendar.gettime ()); return new date[] {STARTDT, calendar.gettime ()};} /** * Get start time to end time based on current time * * @param day * Get time between days * * @param otherday * Starting from previous days * * @return Open The start time and end time */public static date[] Getdaybetween (integer day, integer otherday) {//today's full date dates STARTDT = new Date (); SimpleDateFormat SDF = new SimpleDateFormat ("Yyyy-mm-dd"); String s = Sdf.format (Startdt.gettime ()); try {Startdt = Sdf.parse (s);} catch (ParseException e) {e.printstacktrace ();} Calendar Calendarstart = new GregorianCalendar (); Calendarstart.settime (STARTDT); Calendarstart.add ( Calendarstart.date, -7); Startdt=calendarstart.gettime (); Calendar calendar = new GregorianCalendar (), Calendar.settime (New Date (Startdt.gettime ()-1)), Calendar.add (calendar. DATE, 7); System.out.println (STARTDT); System.out.println (Calendar.gettime ()); return new date[] {startdt,calendar.gettime ()};}} /** * Output:fri Apr 00:00:00 CST Thu APR 23:59:59 CST 2015 */
Java based on the time of day to obtain the time between the first 7 days and the number of days after the query time