Example usage for org.joda.time DateTimeZone getOffset

List of usage examples for org.joda.time DateTimeZone getOffset

Introduction

In this page you can find the example usage for org.joda.time DateTimeZone getOffset.

Prototype

public final int getOffset(ReadableInstant instant) 

Source Link

Document

Gets the millisecond offset to add to UTC to get local time.

Usage

From source file:ru.caramel.juniperbot.core.utils.CommonUtils.java

License:Open Source License

public static String getUTCOffset(DateTimeZone zone) {
    int offset = zone.getOffset(DateTime.now());

    long hours = TimeUnit.MILLISECONDS.toHours(offset);
    long minutes = TimeUnit.MILLISECONDS.toMinutes(offset - TimeUnit.HOURS.toMillis(hours));

    return String.format("UTC%s%d:%02d", hours > 0 ? '+' : '-', hours, minutes);
}