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

/**
 * @param date//from   w w  w.j a v  a2s  .co m
 * @return
 */
public static String encodeTime(Date date) {
    StringBuilder result = new StringBuilder("T_");
    Calendar cal = Calendar.getInstance();
    cal.setTime(date);
    int month = cal.get(Calendar.MONTH) + 1;
    int year = cal.get(Calendar.YEAR);
    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);
    //yyyy-MM-DD'T'kk:mm:ss
    result.append(year).append("-").append((month < 10) ? "0" : "").append(month).append("-")
            .append((day < 10) ? "0" : "").append(day).append("T").append((hour < 10) ? "0" : "").append(hour)
            .append(":").append((minute < 10) ? "0" : "").append(minute).append(":")
            .append((second < 10) ? "0" : "").append(second);
    return result.toString();
}

From source file:com.worldline.easycukes.rest.utils.DateHelper.java

/**
 * Used to convert date value in json date format
 *
 * @param value//from w  ww.j a  v  a  2 s  .  co  m
 * @return
 */
public static String convertDateToJsonFormat(@NonNull final Date value) {
    log.info("setting the date value " + value + " to format json");
    final Calendar calendar = Calendar.getInstance();
    calendar.setTime(value);
    return calendar.get(Calendar.YEAR) + "-" + formatTo2Digit(calendar.get(Calendar.MONTH) + 1) + "-"
            + formatTo2Digit(calendar.get(Calendar.DAY_OF_MONTH)) + "T"
            + formatTo2Digit(calendar.get(Calendar.HOUR_OF_DAY)) + ":"
            + formatTo2Digit(calendar.get(Calendar.MINUTE)) + ":"
            + formatTo2Digit(calendar.get(Calendar.SECOND)) + ":" + calendar.get(Calendar.MILLISECOND) + "Z";
}

From source file:com.my373.common.util.MyDateUtils.java

/**
 * /*  ww  w .  j a v a 2 s  . c  om*/
 * 
 * @param calendar
 * @return
 */
public static Calendar setTimeToMidnight(Calendar calendar) {
    calendar.set(Calendar.HOUR_OF_DAY, 0);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);
    return calendar;
}

From source file:ezbake.services.provenance.graph.Utils.java

public static ezbake.base.thrift.DateTime convertDate2DateTime(final java.util.Date theDate) {
    final Calendar cal = new GregorianCalendar();
    cal.setTime(theDate);/* ww  w.  j av  a2  s  . c o  m*/

    // get calendar parts
    final int year = cal.get(Calendar.YEAR);
    final int month = cal.get(Calendar.MONTH) + 1;
    final int day = cal.get(Calendar.DAY_OF_MONTH);
    final int hour = cal.get(Calendar.HOUR_OF_DAY);
    final int minute = cal.get(Calendar.MINUTE);
    final int second = cal.get(Calendar.SECOND);
    int offsetMinutes = (cal.getTimeZone().getOffset(cal.getTimeInMillis())) / (1000 * 60);

    // set thrift DateTime propertiesd
    final ezbake.base.thrift.DateTime dt = new ezbake.base.thrift.DateTime();
    // Date
    final ezbake.base.thrift.Date date = new ezbake.base.thrift.Date();
    date.setMonth((short) month).setDay((short) day).setYear((short) year);
    dt.setDate(date);

    // Time with TimeZone
    final ezbake.base.thrift.Time t = new ezbake.base.thrift.Time();
    boolean afterUtc = offsetMinutes > 0;
    offsetMinutes = Math.abs(offsetMinutes);
    final ezbake.base.thrift.TimeZone tz = new ezbake.base.thrift.TimeZone((short) (offsetMinutes / 60),
            (short) (offsetMinutes % 60), afterUtc);
    t.setHour((short) hour).setMinute((short) minute).setSecond((short) second).setTz(tz);
    dt.setTime(t);

    return dt;
}

From source file:com.qpark.eip.core.spring.statistics.impl.SysUserStatisticsChannelInvocationListener.java

/**
 * Get a {@link Date}, where hours, minutes, seconds and milliseconds are
 * set to 0.//from w  w w.  java 2 s .com
 *
 * @return the {@link Date} and the corresponding log string.
 */
public static Calendar getRequestDate() {
    Calendar gc = new GregorianCalendar(LOGGING_TIMEZONE);
    gc.set(Calendar.HOUR_OF_DAY, 0);
    gc.set(Calendar.MINUTE, 0);
    gc.set(Calendar.SECOND, 0);
    gc.set(Calendar.MILLISECOND, 0);
    return gc;
}

From source file:com.qpark.eip.core.spring.statistics.dao.StatisticsEraser.java

/**
 * Each day at 0:00 remove old out dated entries.
 *//*from  w  ww.  j  a v  a  2s  .  c  o m*/
@Scheduled(cron = "0 0 0 * * *")
public void erase() {
    Calendar gc = new GregorianCalendar();
    gc.set(Calendar.HOUR_OF_DAY, 0);
    gc.set(Calendar.MINUTE, 0);
    gc.set(Calendar.SECOND, 0);
    gc.set(Calendar.MILLISECOND, 0);
    gc.add(Calendar.WEEK_OF_YEAR, -1 * Math.abs(this.numberOfWeeksToKeepLogs));
    this.dao.eraseSystemUserLog(gc.getTime());
    this.dao.eraseApplicationUserLog(gc.getTime());
    this.dao.eraseFlowLogMessage(gc.getTime());
}

From source file:net.groupbuy.controller.admin.SalesRankingController.java

/**
 * //  w  w  w.j a v  a2s  .co  m
 */
@RequestMapping(value = "/list", method = RequestMethod.GET)
public String list(Date beginDate, Date endDate, Integer count, Model model) {
    if (beginDate != null) {
        Calendar calendar = DateUtils.toCalendar(beginDate);
        calendar.set(Calendar.HOUR_OF_DAY, calendar.getActualMinimum(Calendar.HOUR_OF_DAY));
        calendar.set(Calendar.MINUTE, calendar.getActualMinimum(Calendar.MINUTE));
        calendar.set(Calendar.SECOND, calendar.getActualMinimum(Calendar.SECOND));
        beginDate = calendar.getTime();
    }
    if (endDate != null) {
        Calendar calendar = DateUtils.toCalendar(endDate);
        calendar.set(Calendar.HOUR_OF_DAY, calendar.getActualMaximum(Calendar.HOUR_OF_DAY));
        calendar.set(Calendar.MINUTE, calendar.getActualMaximum(Calendar.MINUTE));
        calendar.set(Calendar.SECOND, calendar.getActualMaximum(Calendar.SECOND));
        endDate = calendar.getTime();
    }
    if (count == null || count <= 0) {
        count = DEFAULT_COUNT;
    }
    model.addAttribute("beginDate", beginDate);
    model.addAttribute("endDate", endDate);
    model.addAttribute("count", count);
    model.addAttribute("data", productService.findSalesList(beginDate, endDate, count));
    return "/admin/sales_ranking/list";
}

From source file:net.groupbuy.controller.admin.PurchaseRankingController.java

/**
 * /*  w  w w . j  ava 2 s  .c  om*/
 */
@RequestMapping(value = "/list", method = RequestMethod.GET)
public String list(Date beginDate, Date endDate, Integer count, Model model) {
    if (beginDate != null) {
        Calendar calendar = DateUtils.toCalendar(beginDate);
        calendar.set(Calendar.HOUR_OF_DAY, calendar.getActualMinimum(Calendar.HOUR_OF_DAY));
        calendar.set(Calendar.MINUTE, calendar.getActualMinimum(Calendar.MINUTE));
        calendar.set(Calendar.SECOND, calendar.getActualMinimum(Calendar.SECOND));
        beginDate = calendar.getTime();
    }
    if (endDate != null) {
        Calendar calendar = DateUtils.toCalendar(endDate);
        calendar.set(Calendar.HOUR_OF_DAY, calendar.getActualMaximum(Calendar.HOUR_OF_DAY));
        calendar.set(Calendar.MINUTE, calendar.getActualMaximum(Calendar.MINUTE));
        calendar.set(Calendar.SECOND, calendar.getActualMaximum(Calendar.SECOND));
        endDate = calendar.getTime();
    }
    if (count == null || count <= 0) {
        count = DEFAULT_COUNT;
    }
    model.addAttribute("beginDate", beginDate);
    model.addAttribute("endDate", endDate);
    model.addAttribute("count", count);
    model.addAttribute("data", memberService.findPurchaseList(beginDate, endDate, count));
    return "/admin/purchase_ranking/list";
}

From source file:com.bstek.dorado.core.el.ExpressionUtilsObject.java

public java.util.Date getToday() {
    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.HOUR_OF_DAY, 0);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);
    calendar.set(Calendar.MILLISECOND, 0);
    return calendar.getTime();
}

From source file:AIR.Common.Utilities.Dates.java

/**
 * @param date/*from  w w w  .  jav a2  s. c o m*/
 * @return returns the midnight time for before date ends e.g. if date is
 *         "10/11/2012 12:10 pm" then this will return "10/11/2012 11:59 pm"
 */
public static Date getEndOfDayDate(Date date) {
    Calendar calendarInstance = Calendar.getInstance();
    calendarInstance.setTime(date);
    calendarInstance.set(Calendar.HOUR_OF_DAY, 23);
    calendarInstance.set(Calendar.MINUTE, 59);
    calendarInstance.set(Calendar.SECOND, 0);
    return calendarInstance.getTime();
}