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

public static long getYearMonthDay(long date) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(date);/*from   w  ww  . ja  va2s  .  c om*/
    calendar.set(Calendar.HOUR_OF_DAY, 0);
    calendar.set(Calendar.SECOND, 0);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.MILLISECOND, 0);
    return calendar.getTimeInMillis();
}

From source file:Main.java

public static Date toNearestWholeMinute(Date d) {
    Calendar c = new GregorianCalendar();
    c.setTime(d);/*from www  .j  a  v a 2  s.com*/

    if (c.get(Calendar.SECOND) >= 30)
        c.add(Calendar.MINUTE, 1);

    c.set(Calendar.SECOND, 0);
    c.set(Calendar.MILLISECOND, 0);

    return c.getTime();
}

From source file:Main.java

public static Long getYesterday() {
    Calendar yesterday = Calendar.getInstance();
    yesterday.setTimeZone(TimeZone.getDefault());

    yesterday.set(Calendar.SECOND, 0);
    yesterday.set(Calendar.MINUTE, 0);
    yesterday.set(Calendar.HOUR_OF_DAY, 1);
    yesterday.set(Calendar.MILLISECOND, 0);

    int day = yesterday.get(Calendar.DAY_OF_YEAR);

    yesterday.set(Calendar.DAY_OF_YEAR, day - 1);

    return yesterday.getTimeInMillis();
}

From source file:Main.java

public static Date addMinutes(Date date, int min) {
    if (date == null) {
        return null;
    }/*from   w  ww. ja  va2s .c  om*/

    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);
    calendar.add(Calendar.MINUTE, min);
    return calendar.getTime();
}

From source file:Main.java

public static int[] getCurrentTime() {
    Calendar now = Calendar.getInstance();
    now.setTimeInMillis(System.currentTimeMillis());
    int[] time = new int[3];
    time[0] = now.get(Calendar.HOUR_OF_DAY);
    time[1] = now.get(Calendar.MINUTE);
    time[2] = now.get(Calendar.SECOND);
    return time;/*from  www .ja va2 s  .  c  om*/
}

From source file:Main.java

private static Calendar prepareCalendar(int hourOfDay, int minute) {
    Calendar calNow = Calendar.getInstance();
    Calendar calSet = (Calendar) calNow.clone();

    calSet.set(Calendar.HOUR_OF_DAY, hourOfDay);
    calSet.set(Calendar.MINUTE, minute);
    calSet.set(Calendar.SECOND, 0);
    calSet.set(Calendar.MILLISECOND, 0);

    if (calSet.compareTo(calNow) <= 0) {
        // Today Set time passed, count to tomorrow
        calSet.add(Calendar.DATE, 1);
    }//from   w w w. ja va2  s  . co  m
    return calSet;
}

From source file:Main.java

public static long intID() {
    Calendar c = Calendar.getInstance();

    int dia = c.get(Calendar.DAY_OF_MONTH);
    int ano = c.get(Calendar.YEAR) - 2010;
    int mes = c.get(Calendar.MONTH) + 1;

    int hora = c.get(Calendar.HOUR_OF_DAY);
    int minuto = c.get(Calendar.MINUTE);
    int segundo = c.get(Calendar.SECOND);
    int milisec = c.get(Calendar.MILLISECOND);

    return Long.parseLong("" + ano + mes + dia + hora + minuto + segundo + milisec);
}

From source file:Main.java

public static Date parseData(String text) {
    Calendar calendar = Calendar.getInstance();
    if (text.contains(":")) {
        String[] time = text.split(":");
        int hours = Integer.parseInt(time[0]);
        calendar.set(Calendar.MINUTE, Integer.parseInt(time[1]));
        calendar.set(Calendar.HOUR_OF_DAY, hours);
        return calendar.getTime();
    } else if (text.contains("/")) {
        String[] date = text.split("/");
        if (date.length == 3) {
            calendar.set(Calendar.DAY_OF_MONTH, Integer.parseInt(date[0]));
            calendar.set(Calendar.MONTH, Integer.parseInt(date[1]) - 1);
            calendar.set(Calendar.YEAR, Integer.parseInt(date[2]));
            calendar.set(Calendar.MINUTE, 0);
            calendar.set(Calendar.HOUR_OF_DAY, 0);
            return calendar.getTime();
        } else if (date.length == 2) {
            calendar.set(Calendar.DAY_OF_MONTH, Integer.parseInt(date[0]));
            calendar.set(Calendar.MONTH, Integer.parseInt(date[1]) - 1);
            calendar.set(Calendar.MINUTE, 0);
            calendar.set(Calendar.HOUR_OF_DAY, 0);
            return calendar.getTime();
        }/*from  ww  w. ja  v  a 2  s  .c o  m*/
    }
    return null;
}

From source file:Main.java

public static Calendar nextMonday() {
    Calendar date = new GregorianCalendar();
    while (date.get(Calendar.DAY_OF_WEEK) != Calendar.MONDAY) {
        date.add(Calendar.DATE, 1);
    }/*  w  w  w . ja v a  2s . c o m*/
    date.set(Calendar.HOUR_OF_DAY, 0);
    date.set(Calendar.MINUTE, 0);
    date.set(Calendar.SECOND, 0);
    date.set(Calendar.MILLISECOND, 0);
    return date;
}

From source file:Main.java

public static String getTimeString(Calendar calendar) {
    if (calendar == null)
        return "";
    String hourString = String.format("%1$02d", calendar.get(Calendar.HOUR_OF_DAY));
    String minuteString = String.format("%1$02d", calendar.get(Calendar.MINUTE));
    StringBuilder dateStringBuilder = new StringBuilder();
    dateStringBuilder.append(hourString).append(":");
    dateStringBuilder.append(minuteString);
    return dateStringBuilder.toString();
}