Example usage for java.time ZoneOffset ofHours

List of usage examples for java.time ZoneOffset ofHours

Introduction

In this page you can find the example usage for java.time ZoneOffset ofHours.

Prototype

public static ZoneOffset ofHours(int hours) 

Source Link

Document

Obtains an instance of ZoneOffset using an offset in hours.

Usage

From source file:Main.java

public static void main(String[] args) {
    ZoneOffset t = ZoneOffset.ofHours(1);
    System.out.println(t);
}

From source file:Main.java

public static void main(String[] args) {
    ZoneOffset zoneOffset1 = ZoneOffset.ofHours(-1);
    System.out.println(zoneOffset1);
    ZoneOffset zoneOffset2 = ZoneOffset.ofHoursMinutes(6, 30);
    System.out.println(zoneOffset2);
    ZoneOffset zoneOffset3 = ZoneOffset.ofHoursMinutesSeconds(9, 30, 45);
    System.out.println(zoneOffset3);
}

From source file:Main.java

public static void main(String[] args) {
    ZoneId offsetOfSixHours = ZoneId.ofOffset("UTC", ZoneOffset.ofHours(-6));
    System.out.println(ZonedDateTime.now().withZoneSameInstant(offsetOfSixHours));

}

From source file:Main.java

public static void main(String[] args) {
    ZonedDateTime nowInAthens = ZonedDateTime.now(ZoneId.of("Europe/Athens"));

    System.out.println(nowInAthens.withZoneSameInstant(ZoneId.ofOffset("UTC", ZoneOffset.ofHours(3))));
}

From source file:Main.java

public static void main(String[] args) {
    Instant instant = Instant.now();
    LocalDateTime dateTimeFromInstant = LocalDateTime.ofInstant(instant, ZoneId.of("America/Los_Angeles"));
    Instant instantFromDateTime = LocalDateTime.now().toInstant(ZoneOffset.ofHours(-2));

    System.out.println(dateTimeFromInstant);

    System.out.println(instantFromDateTime);
}

From source file:Main.java

public static void main(String[] args) {
    // using offsets
    LocalDateTime date = LocalDateTime.of(2013, Month.JULY, 20, 3, 30);
    ZoneOffset offset = ZoneOffset.of("+05:00");

    // 2013-07-20 22:30 +05:00
    OffsetDateTime plusFive = OffsetDateTime.of(date, offset);
    System.out.println(plusFive);

    // 2013-07-19 20:30 -02:00
    OffsetDateTime minusTwo = plusFive.withOffsetSameInstant(ZoneOffset.ofHours(-2));

    System.out.println(minusTwo);
}

From source file:csv.sorting.PrepareWeatherData.java

public static void main(String[] args) throws Exception {

    // Path to read the CSV data from:
    final Path csvStationDataFilePath = FileSystems.getDefault()
            .getPath("C:\\Users\\philipp\\Downloads\\csv\\201503station.txt");
    final Path csvLocalWeatherDataUnsortedFilePath = FileSystems.getDefault()
            .getPath("C:\\Users\\philipp\\Downloads\\csv\\201503hourly.txt");
    final Path csvLocalWeatherDataSortedFilePath = FileSystems.getDefault()
            .getPath("C:\\Users\\philipp\\Downloads\\csv\\201503hourly_sorted.txt");

    // A map between the WBAN and Station for faster Lookups:
    final Map<String, Station> stationMap = getStationMap(csvStationDataFilePath);

    // Holds the List of Sorted DateTimes (including ZoneOffset):
    List<Integer> indices = new ArrayList<>();

    // Comparator for sorting the File:
    Comparator<OffsetDateTime> byMeasurementTime = (e1, e2) -> e1.compareTo(e2);

    // Get the sorted indices from the stream of LocalWeatherData Elements:
    try (Stream<CsvMappingResult<csv.model.LocalWeatherData>> stream = getLocalWeatherData(
            csvLocalWeatherDataUnsortedFilePath)) {

        // Holds the current line index, when processing the input Stream:
        AtomicInteger currentIndex = new AtomicInteger(1);

        // We want to get a list of indices, which sorts the CSV file by measurement time:
        indices = stream/*from  w  w  w .ja  va  2 s . c  om*/
                // Skip the CSV Header:
                .skip(1)
                // Start by enumerating ALL mapping results:
                .map(x -> new ImmutablePair<>(currentIndex.getAndAdd(1), x))
                // Then only take those lines, that are actually valid:
                .filter(x -> x.getRight().isValid())
                // Now take the parsed entity from the CsvMappingResult:
                .map(x -> new ImmutablePair<>(x.getLeft(), x.getRight().getResult()))
                // Take only those measurements, that are also available in the list of stations:
                .filter(x -> stationMap.containsKey(x.getRight().getWban()))
                // Get the OffsetDateTime from the LocalWeatherData, which includes the ZoneOffset of the Station:
                .map(x -> {
                    // Get the matching station:
                    csv.model.Station station = stationMap.get(x.getRight().getWban());
                    // Calculate the OffsetDateTime from the given measurement:
                    OffsetDateTime measurementTime = OffsetDateTime.of(x.getRight().getDate(),
                            x.getRight().getTime(), ZoneOffset.ofHours(0));
                    // Build the Immutable pair with the Index again:
                    return new ImmutablePair<>(x.getLeft(), measurementTime);
                })
                // Now sort the Measurements by their Timestamp:
                .sorted((x, y) -> byMeasurementTime.compare(x.getRight(), y.getRight()))
                // Take only the Index:
                .map(x -> x.getLeft())
                // And turn it into a List:
                .collect(Collectors.toList());
    }

    // Now sorts the File by Line Number:
    writeSortedFileByIndices(csvLocalWeatherDataUnsortedFilePath, indices, csvLocalWeatherDataSortedFilePath);
}

From source file:Main.java

public static LocalDateTime localDateFromTimestamp(Timestamp timestamp) {
    return LocalDateTime.ofInstant(timestamp.toInstant(), ZoneOffset.ofHours(0));
}

From source file:Main.java

public static Timestamp timeZoneAdjustedDate(LocalDateTime due) {
    return Timestamp.from(due.toInstant(ZoneOffset.ofHours(0)));
}

From source file:net.bis5.slack.command.gcal.SlashCommandApi.java

private Date toDate(LocalDateTime dateTime) {
    return Date.from(dateTime.toInstant(ZoneOffset.ofHours(+9)));
}