Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.time.LocalDateTime;
import java.time.Month;
import java.time.OffsetDateTime;
import java.time.ZoneOffset;

public class Main {
    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);
    }
}