Languages
[Edit]
EN

Java - get UTC offset as string (eg +02:00)

3 points
Created by:
Evie-Grace-Noble
351

Quick solution:

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZoneOffset;

public class Example {

    public static void main(String[] args) {

        LocalDateTime time = LocalDateTime.now();
        ZoneOffset offset = time.atZone(ZoneId.systemDefault()).getOffset();
        System.out.println(offset); // +02:00
    }
}

Output:

+02:00

Works in java 1.8+

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join