"JAVA" Determines whether the current date is within a point in time

Source: Internet
Author: User

public static Boolean isindate (date date, String strdatebegin,string strdateend) {SimpleDateFormat SDF = new Simpledatefor Mat ("Yyyy-mm-dd HH:mm:ss"); String strdate = Sdf.format (date),//intercept the current time in seconds int strdateh = Integer.parseint (strdate.substring (one, one)); int strdatem = I Nteger.parseint (strdate.substring (+)); int strdates = Integer.parseint (strdate.substring (17, 19));// Intercept start time hours seconds int strdatebeginh = Integer.parseint (strdatebegin.substring (0, 2)); int strdatebeginm = Integer.parseint ( Strdatebegin.substring (3, 5)); int strdatebegins = Integer.parseint (strdatebegin.substring (6, 8));//intercept end time hours seconds int Strdateendh = Integer.parseint (strdateend.substring (0, 2)), int strdateendm = Integer.parseint (strdateend.substring (3 , 5)); int strdateends = Integer.parseint (strdateend.substring (6, 8)); if (Strdateh >= Strdatebeginh && Strdateh <= Strdateendh) {//Current time hours between start time and end time hours if (Strdateh > Strdatebeginh && strdateh < Strdateen DH) {return true;//the current time hour is equal to the start time hour, and the number of minutes between the start and end of} else if (Strdateh = = Strdatebeginh && strdatem >= strdatebeginm&& strdatem <= strdateendm) {return true;//Current time hours equals start time hours, minutes equals start time minutes, seconds between start and end} else if (Strdateh = = Strdatebeginh && Strdatem = = Strdatebegin m&& strdates >= strdatebegins && strdates <= strdateends) {return true;} The current time hours are large equal to the start time hours, equal to the end time hours, the minutes are small equal to the end time of the Minutes else if (Strdateh >= strdatebeginh && Strdateh = = Strdateendh && Strdatem <= strdateendm) {return true;//the current time hours are large equal to the start time hours, equal to the end time hours, the minutes equal to the end time minutes, the number of seconds is equal to the end time in seconds} else if ( Strdateh >= Strdatebeginh && Strdateh = = strdateendh&& Strdatem = Strdateendm && strdates < = Strdateends) {return true;} else {return false;}} else {return false;}}

  

"JAVA" Determines whether the current date is within a point in 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.