Java Code Examples for java.util.Calendar.getTimeZone()

The following are Jave code examples for showing how to use getTimeZone() of the java.util.Calendar class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: lams   File: FastDateFormat.java   View Source Code Vote up 7 votes
/**
 * {@inheritDoc}
 */
public void appendTo(StringBuffer buffer, Calendar calendar) {
    if (mTimeZoneForced) {
        if (mTimeZone.useDaylightTime() && calendar.get(Calendar.DST_OFFSET) != 0) {
            buffer.append(mDaylight);
        } else {
            buffer.append(mStandard);
        }
    } else {
        TimeZone timeZone = calendar.getTimeZone();
        if (timeZone.useDaylightTime() && calendar.get(Calendar.DST_OFFSET) != 0) {
            buffer.append(getTimeZoneDisplay(timeZone, true, mStyle, mLocale));
        } else {
            buffer.append(getTimeZoneDisplay(timeZone, false, mStyle, mLocale));
        }
    }
}
 
Example 2
Project: airgram   File: FastDatePrinter.java   View Source Code Vote up 6 votes
/**
 * {@inheritDoc}
 */
@Override
public void appendTo(final StringBuffer buffer, final Calendar calendar) {
    final TimeZone zone = calendar.getTimeZone();
    if (zone.useDaylightTime()
            && calendar.get(Calendar.DST_OFFSET) != 0) {
        buffer.append(getTimeZoneDisplay(zone, true, mStyle, mLocale));
    } else {
        buffer.append(getTimeZoneDisplay(zone, false, mStyle, mLocale));
    }
}
 
Example 3
Project: javaide   File: GetCurrentTimeZone.java   View Source Code Vote up 6 votes
public static void main(String[] args) {

    //get Calendar instance
    Calendar now = Calendar.getInstance();

    //get current TimeZone using getTimeZone method of Calendar class
    TimeZone timeZone = now.getTimeZone();

    //display current TimeZone using getDisplayName() method of TimeZone class
    System.out.println("Current TimeZone is : " + timeZone.getDisplayName());
  }
 
Example 4
Project: xmrwallet   File: TransactionInfoAdapter.java   View Source Code Vote up 6 votes
public TransactionInfoAdapter(Context context, OnInteractionListener listener) {
    this.context = context;
    inboundColour = ContextCompat.getColor(context, R.color.tx_green);
    outboundColour = ContextCompat.getColor(context, R.color.tx_red);
    pendingColour = ContextCompat.getColor(context, R.color.tx_pending);
    failedColour = ContextCompat.getColor(context, R.color.tx_failed);
    infoItems = new ArrayList<>();
    this.listener = listener;
    Calendar cal = Calendar.getInstance();
    TimeZone tz = cal.getTimeZone(); //get the local time zone.
    DATETIME_FORMATTER.setTimeZone(tz);
}
 
Example 5
Project: xmrwallet   File: WalletInfoAdapter.java   View Source Code Vote up 6 votes
public WalletInfoAdapter(Context context, OnInteractionListener listener) {
    this.context = context;
    this.infoItems = new ArrayList<>();
    this.listener = listener;
    Calendar cal = Calendar.getInstance();
    TimeZone tz = cal.getTimeZone(); //get the local time zone.
    DATETIME_FORMATTER.setTimeZone(tz);
}
 
Example 6
Project: PlusGram   File: FastDatePrinter.java   View Source Code Vote up 6 votes
/**
 * {@inheritDoc}
 */
@Override
public void appendTo(final StringBuffer buffer, final Calendar calendar) {
    final TimeZone zone = calendar.getTimeZone();
    if (zone.useDaylightTime()
            && calendar.get(Calendar.DST_OFFSET) != 0) {
        buffer.append(getTimeZoneDisplay(zone, true, mStyle, mLocale));
    } else {
        buffer.append(getTimeZoneDisplay(zone, false, mStyle, mLocale));
    }
}
 
Example 7
Project: OpenJSharp   File: DatatypeConverterImpl.java   View Source Code Vote up 6 votes
/** formats time zone specifier. */
private static void formatTimeZone(Calendar cal, StringBuilder buf) {
    TimeZone tz = cal.getTimeZone();

    if (tz == null) {
        return;
    }

    // otherwise print out normally.
    int offset = tz.getOffset(cal.getTime().getTime());

    if (offset == 0) {
        buf.append('Z');
        return;
    }

    if (offset >= 0) {
        buf.append('+');
    } else {
        buf.append('-');
        offset *= -1;
    }

    offset /= 60 * 1000; // offset is in milli-seconds

    formatTwoDigits(offset / 60, buf);
    buf.append(':');
    formatTwoDigits(offset % 60, buf);
}
 
Example 8
Project: parabuild-ci   File: StatisticsUtils.java   View Source Code Vote up 6 votes
/**
   * @param date
   * @param truncateAt
   */
  public static Date truncateDate(final Date date, final int truncateAt) {
    final Calendar source = Calendar.getInstance();
    source.clear();
    source.setTime(date);
    final Calendar result = Calendar.getInstance();
    result.clear();
    result.set(Calendar.YEAR, source.get(Calendar.YEAR));
    final TimeZone sourceTimeZone = source.getTimeZone();
    result.setTimeZone(sourceTimeZone);
    if (truncateAt == Calendar.HOUR_OF_DAY) {
      result.set(Calendar.HOUR_OF_DAY, source.get(Calendar.HOUR_OF_DAY));
      result.set(Calendar.MONTH, source.get(Calendar.MONTH));
      result.set(Calendar.DAY_OF_MONTH, source.get(Calendar.DAY_OF_MONTH));
      result.set(Calendar.DST_OFFSET, source.get(Calendar.DST_OFFSET));
    } else if (truncateAt == Calendar.DAY_OF_MONTH) {
      result.set(Calendar.MONTH, source.get(Calendar.MONTH));
      result.set(Calendar.DAY_OF_MONTH, source.get(Calendar.DAY_OF_MONTH));
//      if (log.isDebugEnabled()) log.debug("result.get(Calendar.HOUR_OF_DAY): " + result.get(Calendar.HOUR_OF_DAY));
    } else if (truncateAt == Calendar.MONTH) {
      result.set(Calendar.MONTH, source.get(Calendar.MONTH));
    } else if (truncateAt == Calendar.YEAR) { // NOPMD
      // do nothing
    } else { // NOPMD
      throw new IllegalArgumentException("Unknown truncateAt");
    }
    return result.getTime();
  }
 
Example 9
Project: openjdk-jdk10   File: DatatypeConverterImpl.java   View Source Code Vote up 6 votes
/** formats time zone specifier. */
private static void formatTimeZone(Calendar cal, StringBuilder buf) {
    TimeZone tz = cal.getTimeZone();

    if (tz == null) {
        return;
    }

    // otherwise print out normally.
    int offset = tz.getOffset(cal.getTime().getTime());

    if (offset == 0) {
        buf.append('Z');
        return;
    }

    if (offset >= 0) {
        buf.append('+');
    } else {
        buf.append('-');
        offset *= -1;
    }

    offset /= 60 * 1000; // offset is in milli-seconds

    formatTwoDigits(offset / 60, buf);
    buf.append(':');
    formatTwoDigits(offset % 60, buf);
}
 
Example 10
Project: openjdk-jdk10   File: DatatypeConverterImpl.java   View Source Code Vote up 6 votes
/** formats time zone specifier. */
private static void formatTimeZone(Calendar cal, StringBuilder buf) {
    TimeZone tz = cal.getTimeZone();

    if (tz == null) {
        return;
    }

    // otherwise print out normally.
    int offset = tz.getOffset(cal.getTime().getTime());

    if (offset == 0) {
        buf.append('Z');
        return;
    }

    if (offset >= 0) {
        buf.append('+');
    } else {
        buf.append('-');
        offset *= -1;
    }

    offset /= 60 * 1000; // offset is in milli-seconds

    formatTwoDigits(offset / 60, buf);
    buf.append(':');
    formatTwoDigits(offset % 60, buf);
}
 
Example 11
Project: calcite-avatica   File: DateTimeUtils.java   View Source Code Vote up 6 votes
/**
 * Gets the active time zone based on a Calendar argument
 */
public static TimeZone getTimeZone(Calendar cal) {
  if (cal == null) {
    return DEFAULT_ZONE;
  }
  return cal.getTimeZone();
}
 
Example 12
Project: yacy_grid_mcp   File: DateParser.java   View Source Code Vote up 5 votes
public static int getTimezoneOffset() {
    Calendar calendar = new GregorianCalendar();
    TimeZone timeZone = calendar.getTimeZone();
    return - (int) TimeUnit.MILLISECONDS.toMinutes(timeZone.getRawOffset()); // we negate the offset because thats the value which is provided by the browser as well 
}
 
Example 13
Project: xmrwallet   File: TxFragment.java   View Source Code Vote up 5 votes
public TxFragment() {
    super();
    Calendar cal = Calendar.getInstance();
    TimeZone tz = cal.getTimeZone(); //get the local time zone.
    TS_FORMATTER.setTimeZone(tz);
}
 
Example 14
Project: OpenJSharp   File: DatatypeConverterImpl.java   View Source Code Vote up 5 votes
/** formats time zone specifier. */
private static void formatTimeZone(Calendar cal, StringBuilder buf) {
    TimeZone tz = cal.getTimeZone();

    if (tz == null) {
        return;
    }

    // otherwise print out normally.
    int offset = tz.getOffset(cal.getTime().getTime());

    if (offset == 0) {
        buf.append('Z');
        return;
    }

    if (offset >= 0) {
        buf.append('+');
    } else {
        buf.append('-');
        offset *= -1;
    }

    offset /= 60 * 1000; // offset is in milli-seconds

    formatTwoDigits(offset / 60, buf);
    buf.append(':');
    formatTwoDigits(offset % 60, buf);
}