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:py.una.pol.karaku.dao.entity.interceptors.TimeInterceptor.java

/**
 * @param c
 */
private void handleDate(Calendar c) {

    c.set(Calendar.HOUR_OF_DAY, 0);
    c.set(Calendar.MINUTE, 0);
}

From source file:DateTime.java

/** Formats the value as an RFC 3339 date/time string. */
public String toStringRfc3339() {

    StringBuilder sb = new StringBuilder();

    Calendar dateTime = new GregorianCalendar(GMT);
    long localTime = value;
    Integer tzShift = this.tzShift;
    if (tzShift != null) {
        localTime += tzShift.longValue() * 60000;
    }/*from w w w  .jav a2 s .  com*/
    dateTime.setTimeInMillis(localTime);

    appendInt(sb, dateTime.get(Calendar.YEAR), 4);
    sb.append('-');
    appendInt(sb, dateTime.get(Calendar.MONTH) + 1, 2);
    sb.append('-');
    appendInt(sb, dateTime.get(Calendar.DAY_OF_MONTH), 2);

    if (!dateOnly) {

        sb.append('T');
        appendInt(sb, dateTime.get(Calendar.HOUR_OF_DAY), 2);
        sb.append(':');
        appendInt(sb, dateTime.get(Calendar.MINUTE), 2);
        sb.append(':');
        appendInt(sb, dateTime.get(Calendar.SECOND), 2);

        if (dateTime.isSet(Calendar.MILLISECOND)) {
            sb.append('.');
            appendInt(sb, dateTime.get(Calendar.MILLISECOND), 3);
        }
    }

    if (tzShift != null) {

        if (tzShift.intValue() == 0) {

            sb.append('Z');

        } else {

            int absTzShift = tzShift.intValue();
            if (tzShift > 0) {
                sb.append('+');
            } else {
                sb.append('-');
                absTzShift = -absTzShift;
            }

            int tzHours = absTzShift / 60;
            int tzMinutes = absTzShift % 60;
            appendInt(sb, tzHours, 2);
            sb.append(':');
            appendInt(sb, tzMinutes, 2);
        }
    }

    return sb.toString();
}

From source file:no.met.jtimeseries.chart.Utility.java

/**
 * The the hour of a time.//from w ww  .  j  a  v a 2 s .com
 * 
 * @param time
 *            The time string. Such as "2012-03-20T14:00:00Z"
 * @return The hour. Such as 14 for the above case
 */
public static int getHourOfDay(Date time) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(time);
    return calendar.get(Calendar.HOUR_OF_DAY);
}

From source file:com.googlecode.jsfFlex.shared.util.JSONConverter.java

public static JSONArray convertJavaDateToASDateConstructorArguments(Calendar toConvert) {
    JSONArray dateConstructorArguments = new JSONArray();

    dateConstructorArguments.put(toConvert.get(Calendar.YEAR));
    dateConstructorArguments.put(toConvert.get(Calendar.MONTH));
    dateConstructorArguments.put(toConvert.get(Calendar.DATE));
    dateConstructorArguments.put(toConvert.get(Calendar.HOUR_OF_DAY));
    dateConstructorArguments.put(toConvert.get(Calendar.MINUTE));
    dateConstructorArguments.put(toConvert.get(Calendar.SECOND));
    dateConstructorArguments.put(toConvert.get(Calendar.MILLISECOND));

    return dateConstructorArguments;
}

From source file:fr.syncarnet.tasks.Task.java

/**
 * @param date//from  ww  w  .j a v  a 2s.  c  o m
 *    The new date in UNIX time
 */
public void setDue(Calendar date) {
    this.modified = new Date().getTime();
    if (date != null) {
        date.set(Calendar.HOUR_OF_DAY, 0);
        date.set(Calendar.MINUTE, 0);
        date.set(Calendar.SECOND, 0);
        date.set(Calendar.MILLISECOND, 0);
    }
    this.due = date;
}

From source file:org.codehaus.mojo.dashboard.report.plugin.chart.time.MarkerTimeChartDecorator.java

public void createChart() {

    XYPlot xyplot = (XYPlot) report.getPlot();
    // if (this.decoratedChart instanceof TimeChartRenderer ) {

    if (this.results != null && !this.results.isEmpty()) {
        Iterator iter1 = this.results.iterator();
        ValueMarker valuemarker = null;/*from  w w w.  ja v a  2s.  com*/
        BlockContainer blockcontainerLabel = new BlockContainer(new ColumnArrangement());
        // blockcontainerLabel.setFrame( new LineBorder() );
        int i = 0;
        while (iter1.hasNext()) {
            Object[] item = (Object[]) iter1.next();
            Date date = (Date) item[1];
            Calendar cal = Calendar.getInstance();
            cal.setTime(date);
            cal.set(Calendar.HOUR_OF_DAY, 0);
            cal.set(Calendar.MINUTE, 0);
            cal.set(Calendar.SECOND, 0);
            valuemarker = new ValueMarker(cal.getTimeInMillis(), ChartColor.createDefaultPaintArray()[i],
                    new BasicStroke(2.0F));

            xyplot.addDomainMarker(valuemarker);
            LegendItem legendLabel = new LegendItem((String) item[0], null, null, null,
                    new Line2D.Double(-7.0, 0.0, 7.0, 0.0), valuemarker.getPaint(), valuemarker.getStroke(),
                    valuemarker.getPaint());

            blockcontainerLabel.add(createLegendItemBlock(legendLabel, i));
            i++;
        }
        createLegendBlock(blockcontainerLabel);
    }
    // }
}

From source file:com.silverpeas.jcrutil.RandomGenerator.java

public static Calendar getOutdatedCalendar() {
    Calendar calendar = Calendar.getInstance();
    calendar.add(Calendar.DAY_OF_MONTH, -(1 + random.nextInt(10)));
    calendar.set(Calendar.HOUR_OF_DAY, getRandomHour());
    calendar.set(Calendar.MINUTE, getRandomMinutes());
    calendar.set(Calendar.SECOND, 0);
    calendar.set(Calendar.MILLISECOND, 0);
    calendar.setLenient(false);/*  ww  w.  ja  v a 2s  .  c om*/
    try {
        calendar.getTime();
    } catch (IllegalArgumentException ie) {
        return getOutdatedCalendar();
    }
    return calendar;
}

From source file:org.jfree.chart.demo.SegmentedHighLowChartDemo.java

/**
 * A demonstration application showing a high-low-open-close chart using a
 * segmented or non-segmented axis./*from   w  w  w .  j  a v  a2  s.c  o  m*/
 *
 * @param title  the frame title.
 * @param useSegmentedAxis use a segmented axis for this demo?
 * @param timelineType Type of timeline to use: 1=Monday through Friday, 2=Intraday
 */
public SegmentedHighLowChartDemo(final String title, final boolean useSegmentedAxis, final int timelineType) {

    super(title);

    System.out.println("\nMaking SegmentedHighLowChartDemo(" + title + ")");

    // create a Calendar object with today's date at midnight
    final Calendar cal = Calendar.getInstance();
    cal.set(Calendar.HOUR_OF_DAY, 0);
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);

    // create a timeline for the demo
    SegmentedTimeline timeline = null;
    switch (timelineType) {
    case 1:
        timeline = SegmentedTimeline.newMondayThroughFridayTimeline();
        break;

    case 2:
        timeline = SegmentedTimeline.newFifteenMinuteTimeline();

        final Calendar cal2 = (Calendar) cal.clone();
        cal2.add(Calendar.YEAR, 1);

        // add 1 year of baseTimeline's excluded segments (Saturdays and Sundays) as
        // exceptions of the intraday timeline
        timeline.addBaseTimelineExclusions(cal.getTime().getTime(), cal2.getTime().getTime());
        break;

    default:
        System.out.println("Invalid timelineType.");
        System.exit(1);
    }

    // create a data set that has data for trading days (Monday through Friday).
    final DefaultHighLowDataset dataset = DemoDatasetFactory.createSegmentedHighLowDataset(timeline,
            cal.getTime());

    final JFreeChart chart;
    if (useSegmentedAxis) {
        chart = ChartFactory.createHighLowChart(title, "Time", "Value", dataset, timeline, true);
    } else {
        chart = ChartFactory.createHighLowChart(title, "Time", "Value", dataset, true);
    }

    final DateAxis axis = (DateAxis) chart.getXYPlot().getDomainAxis();
    axis.setAutoRange(true);
    final TickUnits units = new TickUnits();
    units.add(new DateTickUnit(DateTickUnit.DAY, 1, DateTickUnit.HOUR, 1, new SimpleDateFormat("d-MMM")));
    units.add(new DateTickUnit(DateTickUnit.DAY, 2, DateTickUnit.HOUR, 1, new SimpleDateFormat("d-MMM")));
    units.add(new DateTickUnit(DateTickUnit.DAY, 7, DateTickUnit.DAY, 1, new SimpleDateFormat("d-MMM")));
    units.add(new DateTickUnit(DateTickUnit.DAY, 15, DateTickUnit.DAY, 1, new SimpleDateFormat("d-MMM")));
    units.add(new DateTickUnit(DateTickUnit.DAY, 30, DateTickUnit.DAY, 1, new SimpleDateFormat("d-MMM")));
    axis.setStandardTickUnits(units);

    final NumberAxis vaxis = (NumberAxis) chart.getXYPlot().getRangeAxis();
    vaxis.setAutoRangeIncludesZero(false);

    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));

    setContentPane(chartPanel);

}

From source file:com.autodomum.daylight.algorithm.DaylightAlgorithm.java

@Override
public Date sunrise(final Coordinate coordinate, final Date date) {
    final Calendar calendar = GregorianCalendar.getInstance();
    calendar.setTime(date);/* w  ww.  ja v  a  2  s .c om*/

    final int day = calendar.get(Calendar.DAY_OF_YEAR);

    final double total = length(coordinate.getLatitude(), day);

    final int hours = (int) total;
    final int minutes = (int) ((((double) total) - ((double) hours)) * 60d);

    calendar.set(Calendar.HOUR_OF_DAY, 12);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);
    calendar.set(Calendar.MILLISECOND, 0);

    calendar.add(Calendar.HOUR_OF_DAY, -hours / 2);
    calendar.add(Calendar.MINUTE, -minutes / 2);
    calendar.add(Calendar.MINUTE, (int) localSolarTime(day));

    final TimeZone timeZone = TimeZone.getDefault();

    if (timeZone.inDaylightTime(date)) {
        calendar.add(Calendar.MILLISECOND, timeZone.getDSTSavings());
    }

    return calendar.getTime();
}

From source file:de.bstreit.java.oscr.business.storage.StorageService.java

@Transactional
public void saveSomeBills() {
    // hard to prevent - we can use fix times here, but the database uses
    // system time.
    // maybe modify query so it gets todays date from outside
    assertTrue("Test does only run during datetime :)",
            new Date().getHours() > 1 && new Date().getHours() < 21);

    final Calendar yesterdayOneHourEarlier = Calendar.getInstance();
    yesterdayOneHourEarlier.roll(Calendar.DAY_OF_MONTH, false);
    yesterdayOneHourEarlier.roll(Calendar.HOUR_OF_DAY, false);

    final Calendar yesterdayOneHourLater = Calendar.getInstance();
    yesterdayOneHourLater.roll(Calendar.DAY_OF_MONTH, false);
    yesterdayOneHourLater.roll(Calendar.HOUR_OF_DAY, true);

    final Calendar todayOneHourEarlier = Calendar.getInstance();
    todayOneHourEarlier.roll(Calendar.HOUR_OF_DAY, false);

    final Calendar todayOneHourLater = Calendar.getInstance();
    todayOneHourLater.roll(Calendar.HOUR_OF_DAY, true);

    final TaxInfo taxInfo = new TaxInfo("19%", null, null);
    final Bill billYesterdayOneHourEarlier = billTestFactory.create(taxInfo, yesterdayOneHourEarlier.getTime(),
            yesterdayOneHourEarlier.getTime());

    final Bill billYesterdayOneHourLater = billTestFactory.create(taxInfo, yesterdayOneHourLater.getTime(),
            yesterdayOneHourLater.getTime());

    final Bill billTodayOneHourEarlier = billTestFactory.create(taxInfo, todayOneHourEarlier.getTime(),
            todayOneHourEarlier.getTime());

    final Bill billTodayOneHourLater = billTestFactory.create(taxInfo, todayOneHourLater.getTime(),
            todayOneHourLater.getTime());

    taxInfoRepository.save(taxInfo);//from w  ww .j a  v  a  2  s.  co  m

    billRepository.save(billYesterdayOneHourEarlier);
    billRepository.save(billYesterdayOneHourLater);
    billRepository.save(billTodayOneHourEarlier);
    billRepository.save(billTodayOneHourLater);
}