Java Date Add addCertainTime(java.util.Date date, double hours)

Here you can find the source of addCertainTime(java.util.Date date, double hours)

Description

add Certain Time

License

Open Source License

Declaration

public static java.util.Date addCertainTime(java.util.Date date, double hours) 

Method Source Code

//package com.java2s;

import java.util.Calendar;

public class Main {

    public static java.util.Date addCertainTime(java.util.Date date, double hours) {
        int s = (int) (hours * 60 * 60);
        int hour = s / 3600;
        int min = (s - hour * 3600) / 60;
        int sec = s - hour * 3600 - min * 60;
        java.util.Calendar cal = Calendar.getInstance();
        cal.setTime(date);/*from  w  w  w .  j a  v a  2s  . c o  m*/
        cal.add(Calendar.HOUR, hour);
        cal.add(Calendar.MINUTE, min);
        cal.add(Calendar.SECOND, sec);
        return cal.getTime();
    }
}

Related

  1. add(Date when, int amount, int field)
  2. add(int datePart, int detal, Date date)
  3. add(int field, int value, Date fromDate)
  4. add(long date, int field, int amount)
  5. add30Minutes(Date date)
  6. addDate(Date date, int add)
  7. addDate(Date date, int amount, int type)
  8. addDate(Date date, int field, int add)
  9. addDate(Date date, int k)