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:no.met.jtimeseries.marinogram.MarinogramWrapper.java

private static Date getStartDate() {

    Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
    cal.setTime(new Date());
    cal.set(Calendar.MINUTE, 0);//  w ww  .j  a v a2 s. c  om
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);

    int startHour = 3;
    int offset = (startHour - (cal.get(Calendar.HOUR) % startHour));
    cal.add(Calendar.HOUR, offset);

    System.out.println(cal.getTime() + " - " + offset);

    return cal.getTime();
}

From source file:DateUtils.java

public static final String getDateTimeFromDate(Date dt, String tzString) {
    try {/*from  ww w  .j  a v a  2s  .c  om*/
        GregorianCalendar gc = new GregorianCalendar();
        gc.setTime(dt);
        gc.setTimeZone(TimeZone.getTimeZone(tzString));
        StringBuffer ret = new StringBuffer();
        ret.append(gc.get(Calendar.YEAR));
        ret.append("-");
        ret.append(gc.get(Calendar.MONTH) - 1);
        ret.append("-");
        ret.append(gc.get(Calendar.DATE));
        ret.append(" ");
        ret.append(gc.get(Calendar.HOUR));
        ret.append(":");
        ret.append(gc.get(Calendar.MINUTE));
        ret.append(" ");
        if (gc.get(Calendar.AM_PM) == 0) {
            ret.append("AM");
        } else {
            ret.append("PM");
        }
        return ret.toString();
    } catch (Exception e) {
        return "";
    }
}

From source file:cognitivabrasil.obaa.Technical.Duration.java

@Override
public void setText(String value) {
    String regEx = "P(\\d+Y)?(\\d+M)?(\\d+D)?(T(((\\d+)H)?((\\d+)M)?((\\d+)S)?))?";

    Pattern pattern = Pattern.compile(regEx);
    Matcher matcher;//from w w w  . j  a v  a2s  .c  om

    matcher = pattern.matcher(value);

    if (matcher.find()) {
        String hourString = matcher.group(7);
        String minuteString = matcher.group(9);
        String secondString = matcher.group(10);

        if (hourString != null) {
            this.set(Integer.valueOf(hourString), Calendar.HOUR);
        }
        if (minuteString != null) {
            this.set(Integer.valueOf(minuteString), Calendar.MINUTE);
        }
        //            if(secondString != null) {
        //                this.set(Integer.valueOf(secondString), Calendar.SECOND);
        //            }
    } else {
        if (!StringUtils.isBlank(value)) {
            log.warn("No conseguiu fazer parsing da data: {}", value);
        }
    }

}

From source file:com.acmeair.loader.FlightLoader.java

private static Date getArrivalTime(Date departureTime, int mileage) {
    double averageSpeed = 600.0; // 600 miles/hours
    double hours = (double) mileage / averageSpeed; // miles / miles/hour = hours
    double partsOfHour = hours % 1.0;
    int minutes = (int) (60.0 * partsOfHour);
    Calendar c = Calendar.getInstance();
    c.setTime(departureTime);/* w  w w . j a  v a 2 s. c  o m*/
    c.add(Calendar.HOUR, (int) hours);
    c.add(Calendar.MINUTE, minutes);
    return c.getTime();
}

From source file:com.heliumv.factory.impl.ZeiterfassungCall.java

private Timestamp updateTimeWithNow(Timestamp theirsTs) {
    if (theirsTs == null)
        return null;

    Calendar theirs = Calendar.getInstance();
    theirs.setTimeInMillis(theirsTs.getTime());

    Calendar mine = Calendar.getInstance();
    theirs.set(Calendar.HOUR, mine.get(Calendar.HOUR));
    theirs.set(Calendar.MINUTE, mine.get(Calendar.MINUTE));
    theirs.set(Calendar.SECOND, 0);

    return new Timestamp(theirs.getTimeInMillis());
}

From source file:com.netflix.simianarmy.basic.chaos.BasicChaosMonkey.java

/**
 * Instantiates a new basic chaos monkey.
 * @param ctx//from www  . ja va2 s. c o  m
 *            the ctx
 */
public BasicChaosMonkey(ChaosMonkey.Context ctx) {
    super(ctx);

    this.cfg = ctx.configuration();
    this.monkeyCalendar = ctx.calendar();

    Calendar open = monkeyCalendar.now();
    Calendar close = monkeyCalendar.now();
    open.set(Calendar.HOUR, monkeyCalendar.openHour());
    close.set(Calendar.HOUR, monkeyCalendar.closeHour());

    allChaosTypes = Lists.newArrayList();
    allChaosTypes.add(new ShutdownInstanceChaosType(cfg));
    allChaosTypes.add(new BlockAllNetworkTrafficChaosType(cfg));
    allChaosTypes.add(new DetachVolumesChaosType(cfg));
    allChaosTypes.add(new BurnCpuChaosType(cfg));
    allChaosTypes.add(new BurnIoChaosType(cfg));
    allChaosTypes.add(new KillProcessesChaosType(cfg));
    allChaosTypes.add(new NullRouteChaosType(cfg));
    allChaosTypes.add(new FailEc2ChaosType(cfg));
    allChaosTypes.add(new FailDnsChaosType(cfg));
    allChaosTypes.add(new FailDynamoDbChaosType(cfg));
    allChaosTypes.add(new FailS3ChaosType(cfg));
    allChaosTypes.add(new FillDiskChaosType(cfg));
    allChaosTypes.add(new NetworkCorruptionChaosType(cfg));
    allChaosTypes.add(new NetworkLatencyChaosType(cfg));
    allChaosTypes.add(new NetworkLossChaosType(cfg));

    TimeUnit freqUnit = ctx.scheduler().frequencyUnit();
    if (TimeUnit.DAYS == freqUnit) {
        runsPerDay = ctx.scheduler().frequency();
    } else {
        long units = freqUnit.convert(close.getTimeInMillis() - open.getTimeInMillis(), TimeUnit.MILLISECONDS);
        runsPerDay = units / ctx.scheduler().frequency();
    }
}

From source file:org.testeditor.dashboard.TableDurationTrend.java

/**
 * Formatting duration(ms) in h:m:s:ms.//from w  w  w. ja v a 2 s.  c o  m
 * 
 * @param number
 *            for time formatting
 * @return durationFormat
 */
private String formatDuration(double number) {
    // TODO: refactor - see formatDuration in MyLabelProvider
    Time time = new Time((long) number);
    Calendar cal = Calendar.getInstance();
    cal.setTime(time);
    String durationFormat = cal.get(Calendar.HOUR) - 1 + "h:" + cal.get(Calendar.MINUTE) + "m:"
            + cal.get(Calendar.SECOND) + "s:" + cal.get(Calendar.MILLISECOND) + "ms";
    return durationFormat;
}

From source file:org.openmrs.module.registration.web.controller.ajax.RegistrationAjaxController.java

/**
 * Check whether a day is later than today
 * //from w w  w. ja  v  a  2  s. co m
 * @param date
 * @return
 */
private boolean isLaterToday(Date date) {
    Calendar c = Calendar.getInstance();
    c.setTime(new Date());
    c.set(Calendar.HOUR, 0);
    c.set(Calendar.MINUTE, 0);
    c.set(Calendar.SECOND, 0);
    return date.after(c.getTime());
}

From source file:com.consol.citrus.samples.incident.service.IncidentManagerService.java

/**
 * Gets the default next schedule time which is current timestamp +1h with
 * normalized minutes and seconds./* www .jav a  2s .c om*/
 *
 * @return
 */
private Calendar getScheduledTime() {
    Calendar scheduled = Calendar.getInstance();
    scheduled.add(Calendar.HOUR, 1);

    scheduled.set(Calendar.MINUTE, 0);
    scheduled.set(Calendar.SECOND, 0);
    scheduled.set(Calendar.MILLISECOND, 0);

    return scheduled;
}

From source file:jdchub.module.commands.handlers.BanCommand.java

@Override
public String execute(String cmd, String args, AbstractClient commandOwner) {
    banExpiresDate = new Date();

    this.commandOwner = commandOwner;

    this.nick = null;

    this.reason = null;

    LongOpt[] longOpts = new LongOpt[5];

    longOpts[0] = new LongOpt("nick", LongOpt.REQUIRED_ARGUMENT, null, 'n');
    longOpts[1] = new LongOpt("reason", LongOpt.REQUIRED_ARGUMENT, null, 'r');
    longOpts[2] = new LongOpt("time", LongOpt.REQUIRED_ARGUMENT, null, 't');
    longOpts[3] = new LongOpt("ip", LongOpt.REQUIRED_ARGUMENT, null, 'i');
    longOpts[4] = new LongOpt("mask", LongOpt.REQUIRED_ARGUMENT, null, 'm');

    String[] argArray = CommandUtils.strArgToArray(args);

    Getopt getopt = new Getopt(cmd, argArray, "n:r:t:i:m:", longOpts);

    if (argArray.length < 1) {
        showHelp();/*from   www .j a v  a 2 s .  c  om*/
        return null;
    }

    int c;

    while ((c = getopt.getopt()) != -1) {
        switch (c) {
        case 'n':
            this.nick = getopt.getOptarg();
            break;

        case 'r':
            this.reason = getopt.getOptarg();
            break;

        case 'i':
            this.ip = getopt.getOptarg();
            break;

        case 'm':
            this.mask = getopt.getOptarg();
            break;

        case 't':
            // Valid entries for <time> are Ns, Nm, Nh, Nd, Nw, NM, Ny
            String timeString = getopt.getOptarg();
            int timeType = timeString.charAt(timeString.length() - 1);
            int time;
            try {
                time = Integer.parseInt(timeString.substring(0, timeString.length() - 1));
                if (time <= 0) {
                    throw new NumberFormatException("Invalid time format : time must be greater than 0");
                }
            } catch (NumberFormatException ex) {
                showError("Invalid time format.");
                return "Invalid expires time.";
            }

            Calendar calendar = new GregorianCalendar();
            calendar.setTime(banExpiresDate);

            switch (timeType) {
            case 's':
                timeType = Calendar.SECOND;
                break;

            case 'm':
                timeType = Calendar.MINUTE;
                break;

            case 'h':
                timeType = Calendar.HOUR;
                break;

            case 'd':
                timeType = Calendar.DAY_OF_YEAR;
                break;

            case 'w':
                timeType = Calendar.WEEK_OF_YEAR;
                break;

            case 'M':
                timeType = Calendar.MONTH;
                break;

            case 'Y':
                timeType = Calendar.YEAR;
                break;

            default:
                showError("Invalid time format.");
            }

            calendar.add(timeType, time);
            this.banExpiresDate = calendar.getTime();
            this.banType = Constants.BAN_TEMPORARY;

            break;

        case '?':
            showHelp();
            break;

        default:
            showHelp();
            break;
        }
    }

    return ban();
}