Here you can find the source of formatISO8601TimeZone(TimeZone timeZone, boolean extended)
Converts a TimeZone object to a string that's in ISO-8601 format.
Parameter | Description |
---|
public static String formatISO8601TimeZone(TimeZone timeZone, boolean extended)
//package com.java2s; import java.util.TimeZone; public class Main { /**//from w w w. j a v a 2s. c o m * <p> * Converts a TimeZone object to a string that's in ISO-8601 format. It can * be either basic or extended format. * </p> * * @param - timeZone the timezone to format * @param - extended true to use "extended" format, false not to. Extended * format will put a colon between the hour and minute. * @return the formatted timezone (e.g. "+0530" or "+05:30") */ public static String formatISO8601TimeZone(TimeZone timeZone, boolean extended) { StringBuilder sb = new StringBuilder(); boolean positive = timeZone.getRawOffset() >= 0; int hours = Math.abs(((timeZone.getRawOffset() / 1000) / 60) / 60); int minutes = Math.abs((timeZone.getRawOffset() / 1000) / 60) % 60; sb.append(positive ? '+' : '-'); if (hours < 10) { sb.append('0'); } sb.append(hours); if (extended) { sb.append(':'); } if (minutes < 10) { sb.append('0'); } sb.append(minutes); return sb.toString(); } }