OffsetDateTime withOffsetSameInstant( ZoneOffset offset) example
Description
OffsetDateTime withOffsetSameInstant(ZoneOffset offset)
returns a copy of this OffsetDateTime with the specified offset
ensuring that the result is at the same instant.
Syntax
withOffsetSameInstant
has the following syntax.
public OffsetDateTime withOffsetSameInstant(ZoneOffset offset)
Example
The following example shows how to use withOffsetSameInstant
.
import java.time.OffsetDateTime;
import java.time.ZoneOffset;
// w w w .ja v a2s .c o m
public class Main {
public static void main(String[] args) {
OffsetDateTime o = OffsetDateTime.now();
OffsetDateTime l = o.withOffsetSameInstant(ZoneOffset.UTC);
System.out.println(l);
}
}
The code above generates the following result.