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

static Calendar toNextWholeMinute(Calendar d) {
    Calendar c = new GregorianCalendar();
    c.setTime(d.getTime());//from  w  ww . ja  v a 2  s . com
    c.add(Calendar.MINUTE, 1);
    c.set(Calendar.SECOND, 0);
    return c;
}

From source file:Main.java

public static void trunkDay(Calendar c) {
    c.set(Calendar.HOUR, 0);
    c.set(Calendar.MINUTE, 0);
    c.set(Calendar.SECOND, 0);
}

From source file:Main.java

public static double getJulDate() {
    Calendar cal = Calendar.getInstance();
    int year = cal.get(Calendar.YEAR);
    int month = cal.get(Calendar.MONTH) + 1;
    int day = cal.get(Calendar.DAY_OF_MONTH);
    int hour = cal.get(Calendar.HOUR_OF_DAY);
    int minute = cal.get(Calendar.MINUTE);
    int second = cal.get(Calendar.SECOND);
    double extra = (100.0 * year) + month - 190002.5;
    double julianDay = (367.0 * year) - (Math.floor(7.0 * (year + Math.floor((month + 9.0) / 12.0)) / 4.0))
            + Math.floor((275.0 * month) / 9.0) + day + ((hour + ((minute + (second / 60.0)) / 60.0)) / 24.0)
            + 1721013.5 - ((0.5 * extra) / Math.abs(extra)) + 0.5;
    DecimalFormat sixDigitFormat = new DecimalFormat("#.######");
    return Double.valueOf(sixDigitFormat.format(julianDay));
}

From source file:Main.java

public static Date getDateMinuteBefore(Date originalDate, int minutes) {
    Calendar cal = new GregorianCalendar();
    cal.setTime(originalDate);//from  www  . j a  v  a  2  s .c  om
    cal.add(Calendar.MINUTE, minutes * -1);
    return cal.getTime();
}

From source file:Main.java

/**
 * Retrieves a printable minute value from the calendar to be used within a time.  For example, minute 3 will be
 * returned as 03 (so to display 10:03 instead of 10:3) 
 * @param calendar The calendar object whose minute value to retrieve
 * @return printable minute value from the calendar object
 *//*from  ww w .  ja v a2s .  co m*/
public static String getDisplayableMinute(Calendar calendar) {
    return calendar.get(Calendar.MINUTE) < 10 ? "0" + calendar.get(Calendar.MINUTE)
            : String.valueOf(calendar.get(Calendar.MINUTE));
}

From source file:Main.java

/**
 * Reset the time of a date//from  w w w . ja  v  a2 s .  c o  m
 * @param date the date with time to reset
 * @return the 0 time date.
 */
public static Date zeroTimeDate(Date date) {
    final GregorianCalendar gregorianCalendar = new GregorianCalendar();
    gregorianCalendar.setTime(date);
    gregorianCalendar.set(Calendar.HOUR_OF_DAY, 0);
    gregorianCalendar.set(Calendar.MINUTE, 0);
    gregorianCalendar.set(Calendar.SECOND, 0);
    gregorianCalendar.set(Calendar.MILLISECOND, 0);
    return gregorianCalendar.getTime();
}

From source file:Main.java

public static Bundle bundleCalendar(Calendar cal, long minDate) {
    Bundle args = new Bundle();
    if (cal == null)
        cal = Calendar.getInstance(Locale.getDefault());
    ;//w  ww.  j  a  v  a 2s  . c  om
    args.putInt("year", cal.get(Calendar.YEAR));
    args.putInt("month", cal.get(Calendar.MONTH));
    args.putInt("day", cal.get(Calendar.DAY_OF_MONTH));
    args.putInt("hour", cal.get(Calendar.HOUR_OF_DAY));
    args.putInt("minute", cal.get(Calendar.MINUTE));
    args.putLong("minDate", minDate);
    return args;
}

From source file:Main.java

/**
 * Format a time value for the programme list.
 * //from www. java 2 s.  c o m
 * @param time the time to format
 * @return the formatted time
 */
public static String formatTimeProgrammeList(Calendar time) {
    // TODO: 24 hour clock support
    int hour = time.get(Calendar.HOUR_OF_DAY);
    int minute = time.get(Calendar.MINUTE);
    String ampm = (hour < 12 ? "\n   AM" : "\n   PM");
    if (hour == 0)
        hour = 12;
    else if (hour > 12)
        hour -= 12;
    if (hour < 10 && minute < 10)
        return "  " + hour + ":0" + minute + ampm;
    else if (hour < 10)
        return "  " + hour + ":" + minute + ampm;
    else if (minute < 10)
        return " " + hour + ":0" + minute + ampm;
    else
        return " " + hour + ":" + minute + ampm;
}

From source file:Main.java

/**
 * Format a time value, including the AM/PM indicator.
 * /*from   w  w w  .ja v  a 2  s  .  c  o m*/
 * @param time the time to format
 * @return the formatted time
 */
public static String formatTime(Calendar time) {
    // TODO: 24 hour clock support
    int hour = time.get(Calendar.HOUR_OF_DAY);
    int minute = time.get(Calendar.MINUTE);
    String ampm = (hour < 12 ? " AM" : " PM");
    if (hour == 0)
        hour = 12;
    else if (hour > 12)
        hour -= 12;
    if (minute < 10)
        return hour + ":0" + minute + ampm;
    else
        return hour + ":" + minute + ampm;
}

From source file:Main.java

public static PendingIntent scheduleLocalNotification(Context context, int slot, String title, String message,
        Long alertTime, int repeat) {
    Log.i(TAG, "Scheduling local notification");
    Intent alertIntent = new Intent(getNotificationName(slot));

    PendingIntent pendingIntent = PendingIntent.getBroadcast(context, slot, alertIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    if (alarmManager != null) {
        if (repeat == 0) {
            alarmManager.set(AlarmManager.RTC_WAKEUP, alertTime, pendingIntent);
        } else {/*from   w ww .j  a v  a2s  .  c  o  m*/
            Calendar alarmStartTime = Calendar.getInstance();
            alarmStartTime.add(Calendar.MINUTE, 1);
            alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, alertTime, repeat, pendingIntent);
        }
    }
    return pendingIntent;
}