Here you can find the source of createTimezoneString(String timezoneID)
Parameter | Description |
---|---|
timezoneID | The ID of the timezone to support the hours offset for. |
private static String createTimezoneString(String timezoneID)
//package com.java2s; //License from project: Apache License import org.joda.time.DateTimeZone; import java.util.concurrent.TimeUnit; public class Main { /**//from w w w.j av a 2 s. co m * Taking a timezone ID, this method returns the offset in hours. * * @param timezoneID The ID of the timezone to support the hours offset for. * @return A textual representation of the hours offset for the supported timezone. */ private static String createTimezoneString(String timezoneID) { StringBuilder builder = new StringBuilder(); DateTimeZone timeZone = DateTimeZone.forID(timezoneID); long offsetInMilliseconds = timeZone.toTimeZone().getRawOffset(); long offsetHours = TimeUnit.MILLISECONDS.toHours(offsetInMilliseconds); if (offsetHours == 0) { builder.append("Z"); } else { if (offsetHours < 0) { // Negative builder.append("-"); if (offsetHours < -9) { builder.append(Math.abs(offsetHours)); } else { builder.append(0).append(Math.abs(offsetHours)); } } else { // Positive if (offsetHours > 9) { builder.append(offsetHours); } else { builder.append(0).append(offsetHours); } } builder.append(":00"); } return builder.toString(); } }