Here you can find the source of getTimezoneString(Calendar cal)
public static String getTimezoneString(Calendar cal)
//package com.java2s; /*//from w w w . ja v a2 s. c o m * ***** BEGIN LICENSE BLOCK ***** * Zimbra Collaboration Suite Server * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Synacor, Inc. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software Foundation, * version 2 of the License. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU General Public License for more details. * You should have received a copy of the GNU General Public License along with this program. * If not, see <https://www.gnu.org/licenses/>. * ***** END LICENSE BLOCK ***** */ import java.util.Calendar; public class Main { public static String getTimezoneString(Calendar cal) { int tzoffset = (cal.get(Calendar.ZONE_OFFSET) + cal.get(Calendar.DST_OFFSET)) / 60000; char tzsign = tzoffset > 0 ? '+' : '-'; tzoffset = Math.abs(tzoffset); StringBuilder sb = new StringBuilder(5); sb.append(tzsign); append2DigitNumber(sb, tzoffset / 60); append2DigitNumber(sb, tzoffset % 60); return sb.toString(); } private static StringBuilder append2DigitNumber(StringBuilder sb, int number) { return sb.append((char) ('0' + number / 10)).append((char) ('0' + number % 10)); } }