Java Calendar Time getTimezoneString(Calendar cal)

Here you can find the source of getTimezoneString(Calendar cal)

Description

get Timezone String

License

Open Source License

Declaration

public static String getTimezoneString(Calendar cal) 

Method Source Code

//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));
    }
}

Related

  1. getTimeToString(Calendar argCal)
  2. getTimeValue(Calendar cal)
  3. getTimeYYYYMMDD(Calendar calendar)
  4. getTimeZone(Calendar cal)
  5. getTimeZoneCalendar(final TimeZone timeZone)
  6. hasTime(Calendar cal)
  7. hasTimePart(Calendar calendar)
  8. isEquals(Calendar startTime, Calendar timeCurrent, int type)
  9. isFirstMorning(Calendar time, Calendar previous)