EN
Java - get UTC offset as string (eg +02:00)
3 points
Quick solution:
xxxxxxxxxx
1
import java.time.LocalDateTime;
2
import java.time.ZoneId;
3
import java.time.ZoneOffset;
4
5
public class Example {
6
7
public static void main(String[] args) {
8
9
LocalDateTime time = LocalDateTime.now();
10
ZoneOffset offset = time.atZone(ZoneId.systemDefault()).getOffset();
11
System.out.println(offset); // +02:00
12
}
13
}
Output:
xxxxxxxxxx
1
+02:00
Works in java 1.8+