Example usage for java.util Calendar HOUR

List of usage examples for java.util Calendar HOUR

Introduction

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

Prototype

int HOUR

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

Click Source Link

Document

Field number for get and set indicating the hour of the morning or afternoon.

Usage

From source file:TimeUtil.java

/**
 * convert time in milliseconds into a display string of the form [h]h:mm
 * [am|pm] (traditional) or hh:mm (24 hour format) if using traditional
 * format, the leading 'h' & 'm' will be padded with a space to ensure
 * constant length if less than 10 24 hour format
 * //from w w w . j av  a 2 s  . co m
 * @param msecs
 *            a millisecond time
 * @return TimeString the formatted time string
 */
public static String stringFormat(long msecs) {
    GregorianCalendar cal = new GregorianCalendar();
    StringBuffer sBuf = new StringBuffer(8);

    cal.setTime(new Date(msecs));

    int hour = cal.get(Calendar.HOUR);

    if (hour == 0)
        hour = 12;

    if (hour < 10)
        sBuf.append(" ");

    sBuf.append(Integer.toString(hour));
    sBuf.append(":");

    int minute = cal.get(Calendar.MINUTE);

    if (minute < 10)
        sBuf.append("0");

    sBuf.append(Integer.toString(minute));
    sBuf.append(" ");
    sBuf.append(cal.get(Calendar.AM_PM) == Calendar.AM ? "AM" : "PM");

    return (sBuf.toString());
}

From source file:fll.web.report.finalist.FinalistDBRow.java

@JsonIgnore
public Date getTime() {
    final Calendar cal = Calendar.getInstance();
    cal.set(Calendar.HOUR, getHour());
    cal.set(Calendar.MINUTE, getMinute());
    cal.set(Calendar.SECOND, 0);//from ww w .  ja  v  a 2  s. co  m
    cal.set(Calendar.MILLISECOND, 0);

    return cal.getTime();
}

From source file:be.boyenvaesen.scheduling.HumiditySchedules.java

@Scheduled(fixedRate = 2000)
public void updateIntervalDatabases() {
    log.info("Starting database cleanup");

    Calendar c = Calendar.getInstance();
    Calendar calForCalculations = Calendar.getInstance();
    //Clean records dating till :
    c.add(Calendar.HOUR, -5);
    Date now = new Date();

    List<Humidity> allHumidities = service.getBetweenDates(c.getTime(), now);
    List<HumidityByMinute> humiditiesByMinute = service.getBetweenDatesByInterval(HumidityByMinute.class,
            c.getTime(), now);//from  ww  w  . j av  a2 s .c o m
    List<HumidityByHour> humidityByHour = service.getBetweenDatesByInterval(HumidityByHour.class, c.getTime(),
            now);

    //Group humidities by minute
    Map<Date, List<Humidity>> map = allHumidities.stream().collect(Collectors.groupingBy((t) -> {

        calForCalculations.setTime(t.getMeasured());
        calForCalculations.set(Calendar.SECOND, 0);
        calForCalculations.set(Calendar.MILLISECOND, 0);

        return calForCalculations.getTime();
    }));
    //CALCULATE MINUTES
    map.forEach((t, u) -> {
        HumidityByMinute toCalc = humiditiesByMinute.stream().filter((q) -> {
            return q.getAtTime().compareTo(t) == 0;
        }).findAny().orElse(new HumidityByMinute(t));
        float average = (float) u.stream().mapToDouble(Humidity::getPercentage).average().getAsDouble();
        toCalc.setAveragePercentage(average);
        service.saveByInterval(toCalc);
    });

    List<HumidityByMinute> newByMinute = service.getBetweenDatesByInterval(HumidityByMinute.class, c.getTime(),
            now);
    //Group HumidityByMinute By hour
    Map<Date, List<HumidityByMinute>> mapByHour = newByMinute.stream().collect(Collectors.groupingBy((t) -> {
        calForCalculations.setTime(t.getAtTime());
        calForCalculations.set(Calendar.MINUTE, 0);
        return calForCalculations.getTime();
    }));
    //CALCULATE HOURS
    mapByHour.forEach((t, u) -> {

        HumidityByHour toCalc = humidityByHour.stream().filter((q) -> {
            return q.getAtTime().compareTo(t) == 0;
        }).findAny().orElse(new HumidityByHour(t));
        float average = (float) u.stream().mapToDouble(HumidityByMinute::getAveragePercentage).average()
                .getAsDouble();
        toCalc.setAveragePercentage(average);
        service.saveByInterval(toCalc);

    });
    log.info("finished cleaning database");

}

From source file:com.milos.neo4j.dao.impl.GameDAOImpl.java

@Transactional(readOnly = false, propagation = Propagation.REQUIRED)
@Override/*from ww w.j  a va 2  s  . c  o m*/
public void endOldGames() {
    Calendar calendar = Calendar.getInstance();
    calendar.add(Calendar.HOUR, -1);
    String updateQuery = "MATCH (g:Game) where g.ended = false and g.roundStartDate <= {date} set g.ended = true";
    Map<String, Long> params = new HashMap<>();
    params.put("date", calendar.getTimeInMillis());
    session.query(updateQuery, params, false);
}

From source file:com.tdclighthouse.prototype.utils.TdcUtils.java

public static String getExpiresDate(int hours) {
    GregorianCalendar calendar = new GregorianCalendar();
    calendar.add(Calendar.HOUR, hours);
    Date date = calendar.getTime();
    return dateToRFC1123(date);

}

From source file:com.timesheet.utils.Utils.java

public Date dateModification(Date date, String time) {

    Date modifiedDate = null;/*  w w  w.j  av  a  2  s.com*/

    if (date != null && StringUtils.isNotBlank(time)) {
        String hhStr = time.split(":")[0];
        String mmStr = time.split(":")[1];

        Calendar calendar = Calendar.getInstance();

        calendar.setTime(date);

        calendar.set(Calendar.HOUR, calendar.get(Calendar.HOUR) + Integer.parseInt(hhStr));

        calendar.set(Calendar.MINUTE, calendar.get(Calendar.MINUTE) + Integer.parseInt(mmStr));

        modifiedDate = calendar.getTime();
    }

    return modifiedDate;
}

From source file:com.google.orkut.client.api.Util.java

static String getFormattedTimestamp(long timeMillis) {
    Calendar cal = Calendar.getInstance(TimeZone.getTimeZone(Constants.DateFormatter.UTC));
    cal.setTimeInMillis(timeMillis);/*ww w .  j av a 2s  .co  m*/
    StringBuilder date = new StringBuilder();
    date.append(cal.get(Calendar.YEAR));
    date.append(Constants.DateFormatter.DATE_SEPARATOR);
    date.append(padSingleDigitNum(cal.get(Calendar.MONTH) + 1));
    date.append(Constants.DateFormatter.DATE_SEPARATOR);
    date.append(padSingleDigitNum(cal.get(Calendar.DATE)));
    date.append(Constants.DateFormatter.DATE_DELIM);
    date.append(padSingleDigitNum(cal.get(Calendar.HOUR)));
    date.append(Constants.DateFormatter.TIME_SEPARATOR);
    date.append(padSingleDigitNum(cal.get(Calendar.MINUTE)));
    date.append(Constants.DateFormatter.TIME_SEPARATOR);
    date.append(padSingleDigitNum(cal.get(Calendar.SECOND)));
    date.append(Constants.DateFormatter.TIME_DELIM);
    return date.toString();
}

From source file:siia.business.FlightEventTransformer.java

public FlightDelayEvent convertToDelayEvent(String flightNumberAndDelay) {
    String[] splits = flightNumberAndDelay.split("[+]");
    Flight flight = this.flightScheduler.nextFlightForNumber(splits[0]);
    int hours = Integer.parseInt(splits[1].substring(0, 2));
    int minutes = Integer.parseInt(splits[1].substring(2));
    Calendar cal = Calendar.getInstance();
    cal.setTime(flight.getScheduledDeparture());
    cal.add(Calendar.HOUR, hours);
    cal.add(Calendar.MINUTE, minutes);
    return new FlightDelayEvent(flight, cal.getTime());
}

From source file:org.oncoblocks.centromere.web.test.security.UserController.java

@RequestMapping(value = "", method = RequestMethod.POST)
public @ResponseBody TokenDetails createToken(@AuthenticationPrincipal User user) {
    String token = tokenUtils.createToken(user);
    Calendar calendar = Calendar.getInstance();
    Date now = calendar.getTime();
    calendar.add(Calendar.HOUR, 1);
    Date expires = calendar.getTime();
    return new TokenDetails(token, user.getId(), now, expires);
}