How to use Java to enable requirements to take effect within a specified time __java

Source: Internet
Author: User

For example, the Dragon Boat Festival has an operating activities, only from June 7 to June 11, expired automatically off the line. The following code can implement this functionality.

	String s1= "2016-06-07 00:00:00";
        String s2= "2016-06-12 00:00:00";
        SimpleDateFormat sdf=new SimpleDateFormat ("Yyyy-mm-dd HH:mm:ss");
        try {
			start=sdf.parse (S1);
			End=sdf.parse (s2);
		} catch (ParseException e) {
			e.printstacktrace ();

     * To determine whether the current time in the Dragon Boat Festival activity interval
     * *
    private Boolean isduanwuperiod () {
    	date date=new date ();
    	if (end!=null && start!=null && date.before (end) && date.after (start)) {return
    	} return

The reason to put the start and end time of the build inside the static initialization block is to avoid repetition.

You can then add the Isduanwuperiod method before the feature business function code.

PS: In the actual project can be configured to configure the file time, so more flexible ~

Related Article

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: 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.