Java Date Add add30Minutes(Date date)

Here you can find the source of add30Minutes(Date date)

Description

add Minutes

License

Open Source License

Declaration

public static Date add30Minutes(Date date) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

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

public class Main {
    public static Date add30Minutes(Date date) {
        Calendar currentDate = Calendar.getInstance();

        currentDate.setTime(date);//from   w  w  w . j  a v  a 2s  .com

        int hour = currentDate.get(Calendar.HOUR_OF_DAY);
        int minute = currentDate.get(Calendar.MINUTE);
        int addHour = (minute + 30) / 60;

        minute = (minute + 30) % 60;
        hour = hour + addHour;

        currentDate.set(Calendar.HOUR_OF_DAY, hour);
        currentDate.set(Calendar.MINUTE, minute);

        return currentDate.getTime();
    }
}

Related

  1. add(Date eredeti, int mihez, int mennyit)
  2. add(Date when, int amount, int field)
  3. add(int datePart, int detal, Date date)
  4. add(int field, int value, Date fromDate)
  5. add(long date, int field, int amount)
  6. addCertainTime(java.util.Date date, double hours)
  7. addDate(Date date, int add)
  8. addDate(Date date, int amount, int type)
  9. addDate(Date date, int field, int add)