Example usage for java.util Calendar HOUR_OF_DAY

List of usage examples for java.util Calendar HOUR_OF_DAY

Introduction

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

Prototype

int HOUR_OF_DAY

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

Click Source Link

Document

Field number for get and set indicating the hour of the day.

Usage

From source file:Main.java

public static Date firstTimeOfMonth(Date date) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(date.getTime());

    calendar.set(Calendar.HOUR_OF_DAY, 0);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);
    calendar.set(Calendar.DAY_OF_MONTH, 1);

    Date dateBegin = new Date();
    dateBegin.setTime(calendar.getTimeInMillis());
    return dateBegin;
}

From source file:Main.java

private static void setEndOfDayToCalendar(Calendar c) {
    c.set(Calendar.HOUR_OF_DAY, 23);
    c.set(Calendar.MINUTE, 59);
    c.set(Calendar.SECOND, 59);
}

From source file:Main.java

public static String getTime() {
    Calendar cal = Calendar.getInstance();
    cal.setTimeInMillis(System.currentTimeMillis());
    return cal.get(Calendar.HOUR_OF_DAY) + ":" + cal.get(Calendar.MINUTE) + ":" + cal.get(Calendar.SECOND);
}

From source file:Main.java

public static Date startOfDay(Date origDate) {
    Calendar cal = Calendar.getInstance();
    cal.setTime(origDate);//from w  w  w . ja v a 2 s . co  m
    cal.set(Calendar.HOUR_OF_DAY, 0);
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);

    return cal.getTime();
}

From source file:Main.java

public static Date getMidnight(Date date) {
    Calendar day = Calendar.getInstance();
    day.setTime(date);//ww w  . ja  va 2 s .c om
    day.set(Calendar.HOUR_OF_DAY, 0);
    day.set(Calendar.MINUTE, 0);
    day.set(Calendar.SECOND, 0);
    day.set(Calendar.MILLISECOND, 0);
    day.add(Calendar.DAY_OF_MONTH, 0);

    return day.getTime();
}

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

/**
 * Reset the time of a date/*www  . ja v a 2s.c  om*/
 * @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  . ja va  2 s .c  o m*/
    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 .  j a  v a2 s . c  om
 * @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

public static Date getDateTimeFrom(int year, int monthOfYear, int dayOfMonth) {
    Calendar calendar = Calendar.getInstance();

    calendar.set(Calendar.DAY_OF_MONTH, dayOfMonth);
    calendar.set(Calendar.MONTH, monthOfYear - 1);
    calendar.set(Calendar.YEAR, year);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.HOUR_OF_DAY, 0);
    calendar.set(Calendar.SECOND, 0);
    calendar.set(Calendar.MILLISECOND, 0);

    Date ret = calendar.getTime();
    return ret;/*from  w w  w .j a v  a  2  s.  co m*/
}