List of usage examples for java.util Calendar ZONE_OFFSET
int ZONE_OFFSET
To view the source code for java.util Calendar ZONE_OFFSET.
Click Source Link
get
and set
indicating the raw offset from GMT in milliseconds. From source file:org.exoplatform.cms.common.CommonUtils.java
/** * Get current time GMT/Zulu or UTC,(zone time is 0+GMT) * @return Calendar /*w w w . j a va2s.c o m*/ */ static public Calendar getGreenwichMeanTime() { Calendar calendar = GregorianCalendar.getInstance(); calendar.setLenient(false); int gmtoffset = calendar.get(Calendar.DST_OFFSET) + calendar.get(Calendar.ZONE_OFFSET); calendar.setTimeInMillis(System.currentTimeMillis() - gmtoffset); return calendar; }
From source file:org.openbravo.service.json.DataToJsonConverter.java
private static Date convertToUTC(Date localTime) { Calendar now = Calendar.getInstance(); Calendar calendar = Calendar.getInstance(); calendar.setTime(localTime);/* w w w . j ava 2 s .c o m*/ calendar.set(Calendar.DATE, now.get(Calendar.DATE)); calendar.set(Calendar.MONTH, now.get(Calendar.MONTH)); calendar.set(Calendar.YEAR, now.get(Calendar.YEAR)); int gmtMillisecondOffset = (now.get(Calendar.ZONE_OFFSET) + now.get(Calendar.DST_OFFSET)); calendar.add(Calendar.MILLISECOND, -gmtMillisecondOffset); return calendar.getTime(); }
From source file:com.ibuildapp.romanblack.TableReservationPlugin.utils.TableReservationHTTP.java
/** * Converts time depending on timezone.// w w w . j a va2s .com * * @return formatted string */ public static String timeZoneToString() { int offset = Calendar.getInstance().get(Calendar.ZONE_OFFSET) / 60000; String sign = null; if (offset >= 0) { sign = "+"; } else { sign = "-"; } String houres = Integer.toString(Math.abs(offset) / 60); String minutes = Integer.toString(Math.abs(offset) % 60); if (houres.length() == 1) { houres = "0" + houres; } if (minutes.length() == 1) { minutes = "0" + minutes; } return sign + houres + minutes; }
From source file:com.application.utils.FastDateParser.java
/** * Obtain a Strategy given a field from a SimpleDateFormat pattern * * @param formatField A sub-sequence of the SimpleDateFormat pattern * @param definingCalendar The calendar to obtain the short and long values * @return The Strategy that will handle parsing for the field *//*from www . j a v a 2 s . c om*/ private Strategy getStrategy(final String formatField, final Calendar definingCalendar) { switch (formatField.charAt(0)) { case '\'': if (formatField.length() > 2) { return new CopyQuotedStrategy(formatField.substring(1, formatField.length() - 1)); } //$FALL-THROUGH$ default: return new CopyQuotedStrategy(formatField); case 'D': return DAY_OF_YEAR_STRATEGY; case 'E': return getLocaleSpecificStrategy(Calendar.DAY_OF_WEEK, definingCalendar); case 'F': return DAY_OF_WEEK_IN_MONTH_STRATEGY; case 'G': return getLocaleSpecificStrategy(Calendar.ERA, definingCalendar); case 'H': return MODULO_HOUR_OF_DAY_STRATEGY; case 'K': return HOUR_STRATEGY; case 'M': return formatField.length() >= 3 ? getLocaleSpecificStrategy(Calendar.MONTH, definingCalendar) : NUMBER_MONTH_STRATEGY; case 'S': return MILLISECOND_STRATEGY; case 'W': return WEEK_OF_MONTH_STRATEGY; case 'a': return getLocaleSpecificStrategy(Calendar.AM_PM, definingCalendar); case 'd': return DAY_OF_MONTH_STRATEGY; case 'h': return MODULO_HOUR_STRATEGY; case 'k': return HOUR_OF_DAY_STRATEGY; case 'm': return MINUTE_STRATEGY; case 's': return SECOND_STRATEGY; case 'w': return WEEK_OF_YEAR_STRATEGY; case 'y': return formatField.length() > 2 ? LITERAL_YEAR_STRATEGY : ABBREVIATED_YEAR_STRATEGY; case 'Z': case 'z': return getLocaleSpecificStrategy(Calendar.ZONE_OFFSET, definingCalendar); } }
From source file:org.apache.axis2.databinding.utils.ConverterUtil.java
/** * Converts a given string into a date. Code from Axis1 DateDeserializer. * * @param source/*from ww w.j av a 2s .co m*/ * @return Returns Date. */ public static Date convertToDate(String source) { // the lexical form of the date is '-'? yyyy '-' mm '-' dd zzzzzz? if ((source == null) || source.trim().equals("")) { return null; } source = source.trim(); boolean bc = false; if (source.startsWith("-")) { source = source.substring(1); bc = true; } int year = 0; int month = 0; int day = 0; int timeZoneOffSet = TimeZone.getDefault().getRawOffset(); if (source.length() >= 10) { //first 10 numbers must give the year if ((source.charAt(4) != '-') || (source.charAt(7) != '-')) { throw new RuntimeException("invalid date format (" + source + ") with out - s at correct place "); } year = Integer.parseInt(source.substring(0, 4)); month = Integer.parseInt(source.substring(5, 7)); day = Integer.parseInt(source.substring(8, 10)); if (source.length() > 10) { String restpart = source.substring(10); if (restpart.startsWith("Z")) { // this is a gmt time zone value timeZoneOffSet = 0; } else if (restpart.startsWith("+") || restpart.startsWith("-")) { // this is a specific time format string if (restpart.charAt(3) != ':') { throw new RuntimeException( "invalid time zone format (" + source + ") without : at correct place"); } int hours = Integer.parseInt(restpart.substring(1, 3)); int minits = Integer.parseInt(restpart.substring(4, 6)); timeZoneOffSet = ((hours * 60) + minits) * 60000; if (restpart.startsWith("-")) { timeZoneOffSet = timeZoneOffSet * -1; } } else { throw new RuntimeException("In valid string sufix"); } } } else { throw new RuntimeException("In valid string to parse"); } Calendar calendar = Calendar.getInstance(); calendar.clear(); calendar.setLenient(false); calendar.set(Calendar.YEAR, year); //xml month stars from the 1 and calendar month is starts with 0 calendar.set(Calendar.MONTH, month - 1); calendar.set(Calendar.DAY_OF_MONTH, day); calendar.set(Calendar.ZONE_OFFSET, timeZoneOffSet); // set the day light off set only if time zone if (source.length() >= 10) { calendar.set(Calendar.DST_OFFSET, 0); } calendar.getTimeInMillis(); if (bc) { calendar.set(Calendar.ERA, GregorianCalendar.BC); } return calendar.getTime(); }
From source file:org.sqlite.date.FastDateParser.java
/** * Obtain a Strategy given a field from a SimpleDateFormat pattern * @param formatField A sub-sequence of the SimpleDateFormat pattern * @param definingCalendar The calendar to obtain the short and long values * @return The Strategy that will handle parsing for the field *//* w w w . j a va 2s . c o m*/ private Strategy getStrategy(final String formatField, final Calendar definingCalendar) { switch (formatField.charAt(0)) { case '\'': if (formatField.length() > 2) { return new CopyQuotedStrategy(formatField.substring(1, formatField.length() - 1)); } //$FALL-THROUGH$ default: return new CopyQuotedStrategy(formatField); case 'D': return DAY_OF_YEAR_STRATEGY; case 'E': return getLocaleSpecificStrategy(Calendar.DAY_OF_WEEK, definingCalendar); case 'F': return DAY_OF_WEEK_IN_MONTH_STRATEGY; case 'G': return getLocaleSpecificStrategy(Calendar.ERA, definingCalendar); case 'H': // Hour in day (0-23) return HOUR_OF_DAY_STRATEGY; case 'K': // Hour in am/pm (0-11) return HOUR_STRATEGY; case 'M': return formatField.length() >= 3 ? getLocaleSpecificStrategy(Calendar.MONTH, definingCalendar) : NUMBER_MONTH_STRATEGY; case 'S': return MILLISECOND_STRATEGY; case 'W': return WEEK_OF_MONTH_STRATEGY; case 'a': return getLocaleSpecificStrategy(Calendar.AM_PM, definingCalendar); case 'd': return DAY_OF_MONTH_STRATEGY; case 'h': // Hour in am/pm (1-12), i.e. midday/midnight is 12, not 0 return HOUR12_STRATEGY; case 'k': // Hour in day (1-24), i.e. midnight is 24, not 0 return HOUR24_OF_DAY_STRATEGY; case 'm': return MINUTE_STRATEGY; case 's': return SECOND_STRATEGY; case 'w': return WEEK_OF_YEAR_STRATEGY; case 'y': return formatField.length() > 2 ? LITERAL_YEAR_STRATEGY : ABBREVIATED_YEAR_STRATEGY; case 'X': return ISO8601TimeZoneStrategy.getStrategy(formatField.length()); case 'Z': if (formatField.equals("ZZ")) { return ISO_8601_STRATEGY; } //$FALL-THROUGH$ case 'z': return getLocaleSpecificStrategy(Calendar.ZONE_OFFSET, definingCalendar); } }
From source file:com.application.utils.FastDateParser.java
/** * Construct a Strategy that parses a Text field * * @param field The Calendar field * @param definingCalendar The calendar to obtain the short and long values * @return a TextStrategy for the field and Locale *//*from w ww . j a v a2 s .co m*/ private Strategy getLocaleSpecificStrategy(final int field, final Calendar definingCalendar) { final ConcurrentMap<Locale, Strategy> cache = getCache(field); Strategy strategy = cache.get(locale); if (strategy == null) { strategy = field == Calendar.ZONE_OFFSET ? new TimeZoneStrategy(locale) : new TextStrategy(field, definingCalendar, locale); final Strategy inCache = cache.putIfAbsent(locale, strategy); if (inCache != null) { return inCache; } } return strategy; }
From source file:org.apache.logging.log4j.core.util.datetime.FastDateParser.java
/** * Obtain a Strategy given a field from a SimpleDateFormat pattern * @param formatField A sub-sequence of the SimpleDateFormat pattern * @param definingCalendar The calendar to obtain the short and long values * @return The Strategy that will handle parsing for the field */// w w w . j a v a 2 s.c o m private Strategy getStrategy(final char f, final int width, final Calendar definingCalendar) { switch (f) { default: throw new IllegalArgumentException("Format '" + f + "' not supported"); case 'D': return DAY_OF_YEAR_STRATEGY; case 'E': return getLocaleSpecificStrategy(Calendar.DAY_OF_WEEK, definingCalendar); case 'F': return DAY_OF_WEEK_IN_MONTH_STRATEGY; case 'G': return getLocaleSpecificStrategy(Calendar.ERA, definingCalendar); case 'H': // Hour in day (0-23) return HOUR_OF_DAY_STRATEGY; case 'K': // Hour in am/pm (0-11) return HOUR_STRATEGY; case 'M': return width >= 3 ? getLocaleSpecificStrategy(Calendar.MONTH, definingCalendar) : NUMBER_MONTH_STRATEGY; case 'S': return MILLISECOND_STRATEGY; case 'W': return WEEK_OF_MONTH_STRATEGY; case 'a': return getLocaleSpecificStrategy(Calendar.AM_PM, definingCalendar); case 'd': return DAY_OF_MONTH_STRATEGY; case 'h': // Hour in am/pm (1-12), i.e. midday/midnight is 12, not 0 return HOUR12_STRATEGY; case 'k': // Hour in day (1-24), i.e. midnight is 24, not 0 return HOUR24_OF_DAY_STRATEGY; case 'm': return MINUTE_STRATEGY; case 's': return SECOND_STRATEGY; case 'u': return DAY_OF_WEEK_STRATEGY; case 'w': return WEEK_OF_YEAR_STRATEGY; case 'y': case 'Y': return width > 2 ? LITERAL_YEAR_STRATEGY : ABBREVIATED_YEAR_STRATEGY; case 'X': return ISO8601TimeZoneStrategy.getStrategy(width); case 'Z': if (width == 2) { return ISO8601TimeZoneStrategy.ISO_8601_3_STRATEGY; } //$FALL-THROUGH$ case 'z': return getLocaleSpecificStrategy(Calendar.ZONE_OFFSET, definingCalendar); } }
From source file:org.openbravo.service.json.AdvancedQueryBuilder.java
private String parseSingleClause(JSONObject jsonCriteria) throws JSONException { String operator = jsonCriteria.getString(OPERATOR_KEY); if (operator.equals(OPERATOR_BETWEEN) || operator.equals(OPERATOR_BETWEENINCLUSIVE) || operator.equals(OPERATOR_IBETWEEN) || operator.equals(OPERATOR_IBETWEENINCLUSIVE)) { return parseBetween(jsonCriteria, operator, true); }/* w ww . j av a 2 s . c om*/ Object value = jsonCriteria.has(VALUE_KEY) ? jsonCriteria.get(VALUE_KEY) : null; if (operator.equals(OPERATOR_EXISTS)) { String query = jsonCriteria.getString(EXISTS_QUERY_KEY); String alias = getTypedParameterAlias(); query = query.replace(EXISTS_VALUE_HOLDER, alias); final List<Object> typedValues = new ArrayList<Object>(); final JSONArray values = (JSONArray) value; for (int i = 0; i < values.length(); i++) { typedValues.add(values.getString(i)); } typedParameters.add(typedValues); return query; } String fieldName = jsonCriteria.getString(FIELD_NAME_KEY); // translate to a OR for each value if (value instanceof JSONArray) { final JSONArray jsonArray = (JSONArray) value; final JSONObject advancedCriteria = new JSONObject(); advancedCriteria.put(OPERATOR_KEY, OPERATOR_OR); final JSONArray subCriteria = new JSONArray(); for (int i = 0; i < jsonArray.length(); i++) { final JSONObject subCriterion = new JSONObject(); subCriterion.put(OPERATOR_KEY, operator); subCriterion.put(FIELD_NAME_KEY, fieldName); subCriterion.put(VALUE_KEY, jsonArray.get(i)); subCriteria.put(i, subCriterion); } advancedCriteria.put(CRITERIA_KEY, subCriteria); return parseAdvancedCriteria(advancedCriteria); } // Retrieves the UTC time zone offset of the client if (jsonCriteria.has("minutesTimezoneOffset")) { int clientMinutesTimezoneOffset = Integer .parseInt(jsonCriteria.get("minutesTimezoneOffset").toString()); Calendar now = Calendar.getInstance(); // Obtains the UTC time zone offset of the server int serverMinutesTimezoneOffset = (now.get(Calendar.ZONE_OFFSET) + now.get(Calendar.DST_OFFSET)) / (1000 * 60); // Obtains the time zone offset between the server and the client clientUTCMinutesTimeZoneDiff = clientMinutesTimezoneOffset; UTCServerMinutesTimeZoneDiff = serverMinutesTimezoneOffset; } if (operator.equals(OPERATOR_ISNULL) || operator.equals(OPERATOR_NOTNULL)) { value = null; } // if a comparison is done on an equal date then replace // with a between start time and end time on that date if (operator.equals(OPERATOR_EQUALS) || operator.equals(OPERATOR_EQUALSFIELD)) { final List<Property> properties = JsonUtils.getPropertiesOnPath(getEntity(), fieldName); if (properties.isEmpty()) { return null; } final Property property = properties.get(properties.size() - 1); if (property == null) { return null; } // create the clauses, re-uses the code in parseSimpleClause // which translates a lesserthan/greater than to the end/start // time of a date if (property.isDate() || property.isDatetime() || property.isAbsoluteDateTime()) { if (operator.equals(OPERATOR_EQUALS)) { return "(" + parseSimpleClause(fieldName, OPERATOR_GREATEROREQUAL, value) + " and " + parseSimpleClause(fieldName, OPERATOR_LESSOREQUAL, value) + ")"; } else { return "(" + parseSimpleClause(fieldName, OPERATOR_GREATEROREQUALFIELD, value) + " and " + parseSimpleClause(fieldName, OPERATOR_LESSOREQUALFIElD, value) + ")"; } } } return parseSimpleClause(fieldName, operator, value); }
From source file:org.apache.logging.log4j.core.util.datetime.FastDateParser.java
/** * Construct a Strategy that parses a Text field * @param field The Calendar field/*from ww w . jav a2 s . c o m*/ * @param definingCalendar The calendar to obtain the short and long values * @return a TextStrategy for the field and Locale */ private Strategy getLocaleSpecificStrategy(final int field, final Calendar definingCalendar) { final ConcurrentMap<Locale, Strategy> cache = getCache(field); Strategy strategy = cache.get(locale); if (strategy == null) { strategy = field == Calendar.ZONE_OFFSET ? new TimeZoneStrategy(locale) : new CaseInsensitiveTextStrategy(field, definingCalendar, locale); final Strategy inCache = cache.putIfAbsent(locale, strategy); if (inCache != null) { return inCache; } } return strategy; }