Java Date to Time getTimerDate(String time)

Here you can find the source of getTimerDate(String time)

Description

get Timer Date

License

Apache License

Declaration

public static Date getTimerDate(String time) throws Exception 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.Calendar;
import java.util.Date;

public class Main {

    public static Date getTimerDate(String time) throws Exception {
        String reg = "\\d{2}:\\d{2}:\\d{2}";
        if (time.matches(reg)) {
            String[] temp = time.split(":");
            Calendar c = Calendar.getInstance();
            Date now = new Date();
            c.setTime(now);/*from   w  w  w  .  j a v a 2  s . com*/
            c.set(Calendar.HOUR, Integer.parseInt(temp[0]));
            c.set(Calendar.MINUTE, Integer.parseInt(temp[1]));
            c.set(Calendar.SECOND, Integer.parseInt(temp[2]));
            Date timer = c.getTime();
            if (timer.after(now)) {
                return timer;
            } else {
                c.add(Calendar.DAY_OF_YEAR, 1);
                return c.getTime();
            }
        } else {
            return null;
        }
    }
}

Related

  1. getTimeOnly(Date date)
  2. getTimeOnly(Date date)
  3. getTimeOnly(final Date oDate)
  4. getTimePart(Date dateObject)
  5. getTimePeriod(Date date)
  6. getTimeRoll(Date current, int field, int numberOfRoll)
  7. getTimeStamp(long timeMilis, boolean time, boolean date)
  8. getTimeStampInMin(Date date)
  9. getTimeStampInSec(char separator, Date date)