Example usage for java.time LocalDateTime getHour

List of usage examples for java.time LocalDateTime getHour

Introduction

In this page you can find the example usage for java.time LocalDateTime getHour.

Prototype

public int getHour() 

Source Link

Document

Gets the hour-of-day field.

Usage

From source file:Main.java

public static void main(String[] args) {
    LocalDateTime a = LocalDateTime.of(2014, 6, 30, 12, 01);

    System.out.println(a.getHour());
}

From source file:Main.java

public static void main(String[] argv) {
    LocalDate today = LocalDate.now();
    System.out.println(String.format("Year : %s Month : %s day : %s", today.getYear(), today.getMonthValue(),
            today.getDayOfMonth()));/*from   ww  w .j a va 2  s  .co m*/

    LocalDateTime time = LocalDateTime.now();
    System.out.println(
            String.format("Hour : %s Mins : %s Sec : %s", time.getHour(), time.getMinute(), time.getSecond()));

}

From source file:io.hawkcd.agent.utilities.ReportAppender.java

private static String getTimeStamp() {
    // e.g. [10:51:50:564]:
    LocalDateTime now = LocalDateTime.now();
    String format = String.format("[%02d:%02d:%02d]:", now.getHour(), now.getMinute(), now.getSecond());
    return format;
}

From source file:daylightchart.daylightchart.calculation.RiseSetUtility.java

/**
 * Splits the given rise/ set at midnight.
 *
 * @param riseSet/*  w w w .jav a  2  s.c o  m*/
 *        Rise/ set to split
 * @return Split RiseSet(s)
 */
static RiseSet[] splitAtMidnight(final RiseSet riseSet) {
    if (riseSet == null) {
        return new RiseSet[0];
    }

    final LocalDateTime sunrise = riseSet.getSunrise();
    final LocalDateTime sunset = riseSet.getSunset();

    if (riseSet.getRiseSetType() != RiseSetType.partial && sunset.getHour() < 9) {
        return new RiseSet[] { riseSet.withNewRiseSetTimes(sunrise.toLocalTime(), RiseSet.JUST_BEFORE_MIDNIGHT),
                riseSet.withNewRiseSetTimes(RiseSet.JUST_AFTER_MIDNIGHT, sunset.toLocalTime()) };
    } else if (riseSet.getRiseSetType() != RiseSetType.partial && sunrise.getHour() > 15) {
        return new RiseSet[] { riseSet.withNewRiseSetTimes(RiseSet.JUST_AFTER_MIDNIGHT, sunset.toLocalTime()),
                riseSet.withNewRiseSetTimes(sunrise.toLocalTime(), RiseSet.JUST_BEFORE_MIDNIGHT) };
    } else {
        return new RiseSet[] { riseSet };
    }
}

From source file:net.ceos.project.poi.annotated.bean.MultiTypeObjectBuilder.java

/**
 * Validate the MultiTypeObject based on the object build with the method
 * 'buildMultiTypeObject'//  w w  w .j a va2  s.  c o m
 * 
 * @param toValidate
 *            the object to validate
 */
public static void validateMultiTypeObject(MultiTypeObject toValidate) {
    MultiTypeObject base = buildMultiTypeObject();

    Calendar calendar = Calendar.getInstance();
    calendar.setTime(new Date());

    Calendar calendarUnmarshal = Calendar.getInstance();
    calendarUnmarshal.setTime(toValidate.getDateAttribute());
    assertEquals(calendar.get(Calendar.YEAR), calendarUnmarshal.get(Calendar.YEAR));
    assertEquals(calendar.get(Calendar.MONTH), calendarUnmarshal.get(Calendar.MONTH));
    assertEquals(calendar.get(Calendar.DAY_OF_MONTH), calendarUnmarshal.get(Calendar.DAY_OF_MONTH));
    LocalDate localDate = LocalDate.now();
    assertEquals(localDate.getDayOfMonth(), toValidate.getLocalDateAttribute().getDayOfMonth());
    assertEquals(localDate.getMonth(), toValidate.getLocalDateAttribute().getMonth());
    assertEquals(localDate.getYear(), toValidate.getLocalDateAttribute().getYear());
    LocalDateTime localDateTime = LocalDateTime.now();
    assertEquals(localDateTime.getDayOfMonth(), toValidate.getLocalDateTimeAttribute().getDayOfMonth());
    assertEquals(localDateTime.getMonth(), toValidate.getLocalDateTimeAttribute().getMonth());
    assertEquals(localDateTime.getYear(), toValidate.getLocalDateTimeAttribute().getYear());
    assertEquals(localDateTime.getHour(), toValidate.getLocalDateTimeAttribute().getHour());

    /* it is possible to have an error below due the time of execution of the test */
    assertEquals(localDateTime.getMinute(), toValidate.getLocalDateTimeAttribute().getMinute());

    assertEquals(base.getStringAttribute(), toValidate.getStringAttribute());
    assertEquals(base.getIntegerAttribute(), toValidate.getIntegerAttribute());
    assertEquals(base.getDoubleAttribute(), toValidate.getDoubleAttribute());
    assertEquals(base.getLongAttribute(), toValidate.getLongAttribute());
    assertEquals(base.getBooleanAttribute(), toValidate.getBooleanAttribute());
    assertEquals(base.getJob().getJobCode(), toValidate.getJob().getJobCode());
    assertEquals(base.getJob().getJobFamily(), toValidate.getJob().getJobFamily());
    assertEquals(base.getJob().getJobName(), toValidate.getJob().getJobName());
    assertEquals(base.getIntegerPrimitiveAttribute(), toValidate.getIntegerPrimitiveAttribute());
    assertEquals(base.getDoublePrimitiveAttribute(), toValidate.getDoublePrimitiveAttribute());
    assertEquals(base.getLongPrimitiveAttribute(), toValidate.getLongPrimitiveAttribute());
    assertEquals(base.isBooleanPrimitiveAttribute(), toValidate.isBooleanPrimitiveAttribute());
    assertEquals(base.getAddressInfo().getAddress(), toValidate.getAddressInfo().getAddress());
    assertEquals(base.getAddressInfo().getNumber(), toValidate.getAddressInfo().getNumber());
    assertEquals(base.getAddressInfo().getCity(), toValidate.getAddressInfo().getCity());
    assertEquals(base.getAddressInfo().getCityCode(), toValidate.getAddressInfo().getCityCode());
    assertEquals(base.getAddressInfo().getCountry(), toValidate.getAddressInfo().getCountry());
    assertEquals(base.getFloatAttribute(), toValidate.getFloatAttribute());
    assertEquals(base.getFloatPrimitiveAttribute(), toValidate.getFloatPrimitiveAttribute());
    assertEquals(base.getUnitFamily(), toValidate.getUnitFamily());
    assertEquals(base.getBigDecimalAttribute(), toValidate.getBigDecimalAttribute());
    assertEquals(base.getShortAttribute(), toValidate.getShortAttribute());
    assertEquals(base.getShortPrimitiveAttribute(), toValidate.getShortPrimitiveAttribute());
    // TODO add new validation below
}

From source file:name.nirav.mp.service.analytics.EntityExtractionService.java

public EntityExtractionService(OpenCalaisConfig config, PredictionDB db) {
    this.config = config;
    this.calaisConfig = new CalaisConfig();
    this.calaisConfig.set(CalaisConfig.ConnParam.READ_TIMEOUT, config.readTimeout);
    this.calaisConfig.set(CalaisConfig.ConnParam.CONNECT_TIMEOUT, config.readTimeout);
    this.db = db;
    this.client = new CalaisRestClient(config.licenseKey);
    this.rateLimiter = RateLimiter.create(4);
    Timer timer = new Timer("Calais-ban-reset");
    timer.scheduleAtFixedRate(new TimerTask() {
        public void run() {
            LocalDateTime now = LocalDateTime.now();
            if (now.getHour() >= 23) {
                LOG.info("It is close to midnight {}, resetting callCount", now.getHour());
                callCount = 0;//from w w  w  .  java  2  s. c  o  m
            }
        }
    }, 1000, TimeUnit.MINUTES.toMillis(30));
}

From source file:edu.unibonn.plotting.TimeSeriesPlotter_Sensors.java

private XYDataset createDataset(ArrayList<Sensor> sensors) {
    final TimeSeriesCollection dataset = new TimeSeriesCollection();

    for (int i = 0; i < sensors.size(); i++) {
        Sensor current_sensor = sensors.get(i);

        final TimeSeries s1 = new TimeSeries("Sensor " + i, Hour.class);

        for (int j = 0; j < current_sensor.getDimensions(); j++) {
            LocalDateTime current_record_time = current_sensor.getInitial_record_time().plusHours(j);
            s1.add(new Hour(current_record_time.getHour(), current_record_time.getDayOfMonth(),
                    current_record_time.getMonthValue(), current_record_time.getYear()),
                    current_sensor.getMeasurement(j));
        }/*  w  w w  .  j  a  va 2  s .c o  m*/

        dataset.addSeries(s1);
    }

    dataset.setDomainIsPointsInTime(true);

    return dataset;
}

From source file:edu.unibonn.plotting.TimeSeriesPlotter_Sensors.java

private XYDataset createDataset(ArrayList<Cluster_KMeans> clusters, LocalDateTime from) {
    final TimeSeriesCollection dataset = new TimeSeriesCollection();

    for (int i = 0; i < clusters.size(); i++) {
        Cluster_KMeans current_cluster = clusters.get(i);
        ArrayList<Sensor> member_time_series = current_cluster.getMembership();

        for (Iterator iterator = member_time_series.iterator(); iterator.hasNext();) {
            final TimeSeries s1 = new TimeSeries("Cluster_" + current_cluster.getCluster_id(), Hour.class);

            Sensor current_series = (Sensor) iterator.next();

            for (int j = 0; j < current_series.getDimensions(); j++) {
                LocalDateTime current_record_time = current_series.getInitial_record_time().plusHours(j);
                s1.add(new Hour(current_record_time.getHour(), current_record_time.getDayOfMonth(),
                        current_record_time.getMonthValue(), current_record_time.getYear()),
                        current_series.getMeasurement(j));
            }//from   ww  w  . java2 s. c  o  m

            dataset.addSeries(s1);
        }
    }

    dataset.setDomainIsPointsInTime(true);

    return dataset;
}

From source file:net.atomique.ksar.graph.Graph.java

public int parse_line(LocalDateTime ldt, String s) {

    Second now = new Second(ldt.getSecond(), ldt.getMinute(), ldt.getHour(), ldt.getDayOfMonth(),
            ldt.getMonthValue(), ldt.getYear());

    parse_line(now, s);/*from   w ww  .  j  av a2 s  .  c  o  m*/
    return 0;
}

From source file:net.atomique.ksar.graph.Graph.java

private Second convertLocalDateTimeToSecond(LocalDateTime ldt) {

    int day = ldt.getDayOfMonth();
    int month = ldt.getMonthValue();
    int year = ldt.getYear();
    int hour = ldt.getHour();
    int minute = ldt.getMinute();
    int second = ldt.getSecond();

    return new Second(second, minute, hour, day, month, year);
}