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 getStartOfMonthMs(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.getActualMinimum(Calendar.DAY_OF_MONTH));
    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

/**
 * Add the given amount of minutes to the given calendar. The changes are reflected in the given
 * calendar.//  w w w  .j a va2  s .  c  o m
 * @param calendar The calendar to add the given amount of minutes to.
 * @param minutes The amount of minutes to be added to the given calendar. Negative values are
 * also allowed, it will just go back in time.
 */
public static void addMinutes(Calendar calendar, int minutes) {
    calendar.add(Calendar.MINUTE, minutes);
}

From source file:Util.java

/**
 * Utility for setting the time on a date.
 * @param date//w  w w. ja va2  s  .c o  m
 * @param h
 * @param m
 * @param s
 * @return the date with the time set
 */
public static Date setTime(Date date, int h, int m, int s) {
    if (date == null)
        return null;
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);
    calendar.set(Calendar.HOUR, h);
    calendar.set(Calendar.MINUTE, m);
    calendar.set(Calendar.SECOND, s);
    return calendar.getTime();
}

From source file:Main.java

public static Date getDateTimeFrom(int hour, int minute) {
    Calendar calendar = Calendar.getInstance();

    calendar.set(Calendar.DAY_OF_MONTH, 0);
    calendar.set(Calendar.MONTH, 0);
    calendar.set(Calendar.YEAR, 0);
    calendar.set(Calendar.MINUTE, minute);
    calendar.set(Calendar.HOUR_OF_DAY, hour);
    calendar.set(Calendar.SECOND, 0);
    calendar.set(Calendar.MILLISECOND, 0);

    Date ret = calendar.getTime();
    return ret;/*from ww w.  ja v a2  s  .c  o  m*/
}

From source file:Main.java

public static String getCurrentTimeStampHHMM() {
    Calendar cal = new GregorianCalendar();
    return makeTimeString(cal.get(Calendar.HOUR_OF_DAY), 2) + ":" + makeTimeString(cal.get(Calendar.MINUTE), 2);
}

From source file:Main.java

public static String getCurrentTimeStampHHMMSS() {
    Calendar cal = new GregorianCalendar();
    return makeTimeString(cal.get(Calendar.HOUR_OF_DAY), 2) + ":" + makeTimeString(cal.get(Calendar.MINUTE), 2)
            + ":" + makeTimeString(cal.get(Calendar.SECOND), 2);
}

From source file:Main.java

public static String genererNomFichierInexistant(String directory, String extensionFichier) {
    Calendar c = Calendar.getInstance();
    File aRetourner;//from  www.  j a  va2  s  . c om
    if (extensionFichier.equals("")) {
        aRetourner = new File(
                c.get(Calendar.DAY_OF_MONTH) + "_" + c.get(Calendar.MONTH) + "_" + c.get(Calendar.YEAR) + "_"
                        + c.get(Calendar.HOUR) + ":" + c.get(Calendar.MINUTE) + ":" + c.get(Calendar.SECOND));
    } else if (directory.equals("")) {
        aRetourner = new File(c.get(Calendar.DAY_OF_MONTH) + "_" + c.get(Calendar.MONTH) + "_"
                + c.get(Calendar.YEAR) + "_" + c.get(Calendar.HOUR) + ":" + c.get(Calendar.MINUTE) + ":"
                + c.get(Calendar.SECOND) + "." + extensionFichier);
    } else {
        aRetourner = new File(directory + "/" + c.get(Calendar.DAY_OF_MONTH) + "_" + c.get(Calendar.MONTH) + "_"
                + c.get(Calendar.YEAR) + "_" + c.get(Calendar.HOUR) + ":" + c.get(Calendar.MINUTE) + ":"
                + c.get(Calendar.SECOND) + "." + extensionFichier);
    }

    return aRetourner.getPath();
}

From source file:Main.java

public static String getCurrentTime() {
    DecimalFormat df = new DecimalFormat("00");
    Calendar c = Calendar.getInstance();
    String currentTime = c.get(Calendar.YEAR)// + "-"
            + df.format((c.get(Calendar.MONTH) + 1)) // + "-"
            + df.format(c.get(Calendar.DAY_OF_MONTH))// + "-"
            + df.format(c.get(Calendar.HOUR_OF_DAY)) // + "-"
            + df.format(c.get(Calendar.MINUTE))// + "-"
            + df.format(c.get(Calendar.SECOND));
    return currentTime;
}

From source file:Main.java

/**
 * Returns Date object of the next day of d.
 * @return/*from   www .j a  v a 2  s .c o m*/
 */
public static Date getNextDay(Date d) {
    Calendar c = Calendar.getInstance();
    if (d != null)
        c.setTime(d);
    c.set(Calendar.HOUR_OF_DAY, 0);
    c.set(Calendar.MINUTE, 0);
    c.set(Calendar.SECOND, 0);
    c.set(Calendar.MILLISECOND, 0);
    c.add(Calendar.DAY_OF_MONTH, 1);
    return c.getTime();
}

From source file:Main.java

public static boolean isInTimeNow(int start, int end) {
    Calendar calendar = new ThreadLocal<Calendar>() {
        protected Calendar initialValue() {
            return Calendar.getInstance();
        }//w w w.  j  a v a2  s  .co m
    }.get();
    long current = System.currentTimeMillis();
    calendar.setTimeInMillis(current);
    calendar.set(Calendar.HOUR_OF_DAY, 0);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);
    calendar.set(Calendar.MILLISECOND, 0);
    long originToday = calendar.getTimeInMillis();
    long distance = current - originToday;
    if (start <= distance && distance <= end) {
        return true;
    }

    return false;
}