Here you can find the source of formatTimeZoneOffset(TimeZone timeZone)
Parameter | Description |
---|---|
timeZone | a time zone. |
public static String formatTimeZoneOffset(TimeZone timeZone)
//package com.java2s; /*/* w w w.j a v a 2 s . c o m*/ * Copyright (c) 2015-2016 QuartzDesk.com. * Licensed under the MIT license (https://opensource.org/licenses/MIT). */ import java.util.TimeZone; public class Main { /** * Returns the formatted offset of the specified time zone at the current local time. * * @param timeZone a time zone. * @return the formatted offset (e.g. UTC+01:00). */ public static String formatTimeZoneOffset(TimeZone timeZone) { int offsetSeconds = timeZone.getOffset(System.currentTimeMillis()) / 1000; int offsetHours = Math.abs(offsetSeconds / 3600); int offsetMinutes = (Math.abs(offsetSeconds) - (offsetHours * 3600)) / 60; StringBuilder offset = new StringBuilder("UTC"); if (offsetSeconds >= 0) { offset.append('+'); } else { offset.append('-'); } if (offsetHours < 10) offset.append('0'); offset.append(offsetHours); offset.append(':'); if (offsetMinutes < 10) offset.append('0'); offset.append(offsetMinutes); return offset.toString(); } }