Example usage for java.util Calendar MINUTE

List of usage examples for java.util Calendar MINUTE

Introduction

In this page you can find the example usage for java.util Calendar MINUTE.

Prototype

int MINUTE

To view the source code for java.util Calendar MINUTE.

Click Source Link

Document

Field number for get and set indicating the minute within the hour.

Usage

From source file:Main.java

/**
 * Get the SunSet for the given date/*from   w  ww  . j a va 2s. co m*/
 * @param date - input date
 * @return - Date with time specifying the Sun Set
 */
public static Date getSunSet(Date date) {
    Calendar cal = Calendar.getInstance();
    cal.setTime(date);
    cal.set(Calendar.HOUR_OF_DAY, 18);
    cal.set(Calendar.MINUTE, 00);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);
    Date ret = cal.getTime();
    return ret;
}

From source file:Main.java

/**
 * getDateEnd/*from   ww w  .j  a va2 s.  com*/
 * @param date the date that needs to be converted to an end date
 * @return a date at 11:59 PM
 */
public static Date getDateEnd(Date date) {
    Calendar cal = Calendar.getInstance();
    cal.setTime(date);
    cal.set(Calendar.HOUR_OF_DAY, 23);
    cal.set(Calendar.MINUTE, 59);
    cal.set(Calendar.SECOND, 59);
    cal.set(Calendar.MILLISECOND, 59);
    long time = cal.getTimeInMillis();
    date.setTime(time);
    return date;
}

From source file:Main.java

/**
 * Get the SunRise for the given date/*  w w w .j a  v  a2s  .c  om*/
 * @param date - input date
 * @return - Date with time specifying the Sun Rise
 */
public static Date getSunRise(Date date) {
    Calendar cal = Calendar.getInstance();
    cal.setTime(date);
    cal.set(Calendar.HOUR_OF_DAY, 06);
    cal.set(Calendar.MINUTE, 00);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);
    Date ret = cal.getTime();
    return ret;
}

From source file:Main.java

public static String getCurrentTimeString(int s) {
    //s=0 for star time s=1 for end time
    Calendar currentCalendar = Calendar.getInstance();
    int hours = currentCalendar.get(Calendar.HOUR_OF_DAY);
    int minutes = currentCalendar.get(Calendar.MINUTE);

    if (minutes < 30) {
        currentCalendar.setTimeInMillis(currentCalendar.getTimeInMillis() + (30 - minutes) * 60 * 1000);
    }//w  w w .  ja v a  2s  . com
    if (minutes > 30) {
        currentCalendar.setTimeInMillis(currentCalendar.getTimeInMillis() + (60 - minutes) * 60 * 1000);
    }
    if (s == 1)
        currentCalendar.setTimeInMillis(currentCalendar.getTimeInMillis() + 30 * 60 * 1000);

    return timeFormat.format(currentCalendar.getTimeInMillis());
}

From source file:Main.java

public static long getEndOfDayMs(int year, int month, int day) {
    final Calendar date = Calendar.getInstance();

    date.set(Calendar.YEAR, year);
    date.set(Calendar.MONTH, month);
    date.set(Calendar.DAY_OF_MONTH, day);
    date.set(Calendar.HOUR_OF_DAY, date.getActualMaximum(Calendar.HOUR_OF_DAY));
    date.set(Calendar.MINUTE, date.getActualMaximum(Calendar.MINUTE));
    date.set(Calendar.SECOND, date.getActualMaximum(Calendar.SECOND));
    date.set(Calendar.MILLISECOND, date.getActualMaximum(Calendar.MILLISECOND));
    return date.getTimeInMillis();
}

From source file:Main.java

public static long getStartOfDayMs(int year, int month, int day) {
    final Calendar date = Calendar.getInstance();

    date.set(Calendar.YEAR, year);
    date.set(Calendar.MONTH, month);
    date.set(Calendar.DAY_OF_MONTH, day);
    date.set(Calendar.HOUR_OF_DAY, date.getActualMinimum(Calendar.HOUR_OF_DAY));
    date.set(Calendar.MINUTE, date.getActualMinimum(Calendar.MINUTE));
    date.set(Calendar.SECOND, date.getActualMinimum(Calendar.SECOND));
    date.set(Calendar.MILLISECOND, date.getActualMinimum(Calendar.MILLISECOND));
    return date.getTimeInMillis();
}

From source file:Main.java

/**
 * Takes in a duration in minutes and a start timestamp and returns
 * the formatted time that is timestamp + duration
 *///  ww w  .jav  a2  s. c o  m
public static String getTimeAfterStart(long startTime, int duration) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(startTime);
    calendar.add(Calendar.MINUTE, duration);

    int minute = calendar.get(Calendar.MINUTE);
    String minuteString = "";
    if (minute < 10)
        minuteString = "0" + minute;
    else
        minuteString = "" + minute;
    String timeString = calendar.get(Calendar.HOUR) + ":" + minuteString + " "
            + AM_PM[calendar.get(Calendar.AM_PM)];
    return timeString;
}

From source file:Main.java

/**
 * Remove the time of a date value/*from   w w  w  .ja  v a 2s. c  o m*/
 *
 * @param date Date to remove the time part
 * @return A date with its time set to 00:00:00
 */
public static Date removeTime(Date date) {
    GregorianCalendar gc = new GregorianCalendar();
    gc.setTime(date);
    gc.set(Calendar.HOUR_OF_DAY, 0);
    gc.set(Calendar.MINUTE, 0);
    gc.set(Calendar.SECOND, 0);
    gc.set(Calendar.MILLISECOND, 0);
    return gc.getTime();
}

From source file:Main.java

public static int getMinute(long date) {
    Calendar c = Calendar.getInstance();
    c.setTimeInMillis(date);/*from   w w  w  .j  a v a  2  s . c o  m*/
    return c.get(Calendar.MINUTE);
}

From source file:Main.java

public static long getEndOfMonthMs(int year, int month) {
    final Calendar date = Calendar.getInstance();

    date.set(Calendar.YEAR, year);
    date.set(Calendar.MONTH, month);
    date.set(Calendar.DAY_OF_MONTH, date.getActualMaximum(Calendar.DAY_OF_MONTH));
    date.set(Calendar.HOUR_OF_DAY, date.getActualMaximum(Calendar.HOUR_OF_DAY));
    date.set(Calendar.MINUTE, date.getActualMaximum(Calendar.MINUTE));
    date.set(Calendar.SECOND, date.getActualMaximum(Calendar.SECOND));
    date.set(Calendar.MILLISECOND, date.getActualMaximum(Calendar.MILLISECOND));
    return date.getTimeInMillis();
}