Java Hour Calculate plusHours(Date date, int hours)

Here you can find the source of plusHours(Date date, int hours)

Description

plus Hours

License

Open Source License

Declaration

public static Date plusHours(Date date, int hours) 

Method Source Code

//package com.java2s;

import java.text.SimpleDateFormat;
import java.util.*;

public class Main {
    private final static SimpleDateFormat sdfTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    public static Date plusHours(Date date, int hours) {
        if (date == null)
            date = getToday();//from  ww w. j ava2 s . c  om
        return changeHours(date, hours);
    }

    public static Date getToday() {
        return new Date();
    }

    private static Date changeHours(Date date, int hours) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        cal.add(Calendar.HOUR_OF_DAY, hours);
        return cal.getTime();
    }

    public static String getTime() {
        return sdfTime.format(new Date());
    }
}

Related

  1. isValidTime(int hour, int minute, boolean ampm)
  2. isValidTime(int hour, int minute, boolean ampm)
  3. parseDate(String date, String hours)
  4. plusHour(int hour)
  5. plusHour(String dateStr, int hour)
  6. plusOrMinusHours(Date dateTime, long count)
  7. setHours(Date date, int amount)
  8. toStringHour(int hours, int minutes, int seconds, int millis)
  9. toTime(int hours, int minutes, int seconds)