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

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.