com.pureinfo.srm.config.notice.TestTimer.java Source code

Java tutorial

Introduction

Here is the source code for com.pureinfo.srm.config.notice.TestTimer.java

Source

package com.pureinfo.srm.config.notice;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Timer;
import java.util.TimerTask;

import org.apache.commons.lang.time.DateUtils;

/**
 * PureInfo Quake
 * @(#)TestTimer.java   1.0 Nov 13, 2005
 * 
 * Copyright(c) 2004-2005, PureInfo Information Technology Corp. Ltd. 
 * All rights reserved, see the license file.
 * 
 * www.pureinfo.com.cn
 */

/**
 * <P>
 * Created on Nov 13, 2005 6:40:39 PM <BR>
 * Last modified on Nov 13, 2005
 * </P>
 * 
 * @author Freeman.Hu
 * @version 1.0, Nov 13, 2005
 * @since Quake 1.0
 */
public class TestTimer {
    static DateFormat format = new SimpleDateFormat("HH:mm");

    public static void main(String[] args) throws ParseException {
        Calendar start = new GregorianCalendar();
        start.setTime(format.parse("18:40"));
        Calendar cal = new GregorianCalendar();
        start.set(Calendar.YEAR, cal.get(Calendar.YEAR));
        start.set(Calendar.MONTH, cal.get(Calendar.MONTH));
        start.set(Calendar.DAY_OF_MONTH, cal.get(Calendar.DAY_OF_MONTH));
        while (start.before(cal)) {
            start.setTimeInMillis(start.getTimeInMillis() + DateUtils.MILLIS_PER_MINUTE);
        }
        new Timer().scheduleAtFixedRate(new test1(), start.getTime(), DateUtils.MILLIS_PER_MINUTE);
    }

    public static class test1 extends TimerTask {

        /**
         * @see java.util.TimerTask#run()
         */
        public void run() {
            System.out.println(new Date() + "hi");
        }

    }
}