Java Code Examples for java.util.TimeZone#setRawOffset()
The following examples show how to use
java.util.TimeZone#setRawOffset() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GanttLanguage.java From ganttproject with GNU General Public License v3.0 | 5 votes |
public void setLocale(Locale locale) { currentLocale = locale; CalendarFactoryImpl.setLocaleImpl(); Locale.setDefault(locale); int defaultTimezoneOffset = TimeZone.getDefault().getRawOffset() + TimeZone.getDefault().getDSTSavings(); TimeZone utc = TimeZone.getTimeZone("UTC"); utc.setRawOffset(defaultTimezoneOffset); TimeZone.setDefault(utc); applyDateFormatLocale(getDateFormatLocale(locale)); InternationalizationKt.setLocale(locale); fireLanguageChanged(); }
Example 2
Source File: NGWUtil.java From android_maplib with GNU Lesser General Public License v3.0 | 5 votes |
private static void readNGWDate(Feature feature, JsonReader reader, String fieldName) throws IOException { reader.beginObject(); int nYear = 1900; int nMonth = 1; int nDay = 1; int nHour = 0; int nMinute = 0; int nSecond = 0; while (reader.hasNext()) { String name = reader.nextName(); if (name.equals(NGWUtil.NGWKEY_YEAR)) { nYear = reader.nextInt(); } else if (name.equals(NGWUtil.NGWKEY_MONTH)) { nMonth = reader.nextInt(); } else if (name.equals(NGWUtil.NGWKEY_DAY)) { nDay = reader.nextInt(); } else if (name.equals(NGWUtil.NGWKEY_HOUR)) { nHour = reader.nextInt(); } else if (name.equals(NGWUtil.NGWKEY_MINUTE)) { nMinute = reader.nextInt(); } else if (name.equals(NGWUtil.NGWKEY_SECOND)) { nSecond = reader.nextInt(); } else { reader.skipValue(); } } TimeZone timeZone = TimeZone.getDefault(); timeZone.setRawOffset(0); // set to UTC Calendar calendar = new GregorianCalendar(timeZone); calendar.set(nYear, nMonth - 1, nDay, nHour, nMinute, nSecond); calendar.set(Calendar.MILLISECOND, 0); // we must to reset millis feature.setFieldValue(fieldName, calendar.getTimeInMillis()); reader.endObject(); }
Example 3
Source File: StandardUnitFormat.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 4 votes |
public final Calendar zoneExpr(Calendar calendar) throws ParseException { int sign = 1; int zoneHour; int zoneMinute = 0; Token token; TimeZone timeZone; switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) { case PLUS: case MINUS: case UINT: switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) { case PLUS: case MINUS: sign = sign(); break; default: jj_la1[32] = jj_gen;; } zoneHour = unsignedInteger(); switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) { case COLON: case UINT: switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) { case COLON: jj_consume_token(COLON); break; default: jj_la1[33] = jj_gen;; } zoneMinute = unsignedInteger(); break; default: jj_la1[34] = jj_gen;; } if (zoneHour >= 100) { zoneMinute += zoneHour % 100; zoneHour /= 100; } if (zoneHour > 23 || zoneMinute > 59) { { if (true) throw new ParseException("invalid time-zone in timestamp"); } } timeZone = TimeZone.getTimeZone("UTC"); timeZone.setRawOffset(sign * (zoneHour * 60 + zoneMinute) * 60 * 1000); break; case NAME: token = jj_consume_token(NAME); timeZone = TimeZone.getTimeZone(token.image); break; default: jj_la1[35] = jj_gen; jj_consume_token(-1); throw new ParseException(); } calendar.setTimeZone(timeZone); { if (true) return calendar; } throw new Error("Missing return statement in function"); }
Example 4
Source File: DateConverter.java From gcs with Mozilla Public License 2.0 | 4 votes |
static boolean parseTZoffset(String text, GregorianCalendar cal, ParsePosition initialWhere) { ParsePosition where = new ParsePosition(initialWhere.getIndex()); TimeZone tz = new SimpleTimeZone(0, "GMT"); int tzHours, tzMin; char sign = skipOptionals(text, where, "Z+- "); boolean hadGMT = (sign == 'Z' || skipString(text, "GMT", where) || skipString(text, "UTC", where)); sign = (!hadGMT) ? sign : skipOptionals(text, where, "+- "); tzHours = parseTimeField(text, where, 2, -999); skipOptionals(text, where, "\': "); tzMin = parseTimeField(text, where, 2, 0); skipOptionals(text, where, "\' "); if (tzHours != -999) { // we parsed a time zone in default format int hrSign = (sign == '-' ? -1 : 1); tz.setRawOffset(restrainTZoffset(hrSign * (tzHours * MILLIS_PER_HOUR + tzMin * (long) MILLIS_PER_MINUTE))); updateZoneId(tz); } else if ( ! hadGMT) { // try to process as a name; "GMT" or "UTC" has already been processed String tzText = text.substring(initialWhere.getIndex()).trim(); tz = TimeZone.getTimeZone(tzText); // getTimeZone returns "GMT" for unknown ids if ("GMT".equals(tz.getID())) { // no timezone in text, cal amd initialWhere are unchanged return false; } else { // we got a tz by name; use it where.setIndex(text.length()); } } adjustTimeZoneNicely(cal, tz); initialWhere.setIndex(where.getIndex()); return true; }
Example 5
Source File: DateConverter.java From sambox with Apache License 2.0 | 4 votes |
static boolean parseTZoffset(String text, GregorianCalendar cal, ParsePosition initialWhere) { ParsePosition where = new ParsePosition(initialWhere.getIndex()); TimeZone tz = new SimpleTimeZone(0, "GMT"); int tzHours, tzMin; char sign = skipOptionals(text, where, "Z+- "); boolean hadGMT = (sign == 'Z' || skipString(text, "GMT", where) || skipString(text, "UTC", where)); sign = (!hadGMT) ? sign : skipOptionals(text, where, "+- "); tzHours = parseTimeField(text, where, 2, -999); skipOptionals(text, where, "\': "); tzMin = parseTimeField(text, where, 2, 0); skipOptionals(text, where, "\' "); if (tzHours != -999) { // we parsed a time zone in default format int hrSign = (sign == '-' ? -1 : 1); tz.setRawOffset(restrainTZoffset( hrSign * (tzHours * MILLIS_PER_HOUR + tzMin * (long) MILLIS_PER_MINUTE))); updateZoneId(tz); } else if (!hadGMT) { // try to process as a name; "GMT" or "UTC" has already been processed String tzText = text.substring(initialWhere.getIndex()).trim(); tz = TimeZone.getTimeZone(tzText); // getTimeZone returns "GMT" for unknown ids if ("GMT".equals(tz.getID())) { // no timezone in text, cal amd initialWhere are unchanged return false; } else { // we got a tz by name; use it where.setIndex(text.length()); } } adjustTimeZoneNicely(cal, tz); initialWhere.setIndex(where.getIndex()); return true; }
Example 6
Source File: Feature.java From android_maplib with GNU Lesser General Public License v3.0 | 4 votes |
public void fromCursor(Cursor cursor) { if (null == cursor) { return; } mId = cursor.getLong(cursor.getColumnIndex(FIELD_ID)); try { mGeometry = GeoGeometryFactory.fromBlob(cursor.getBlob(cursor.getColumnIndex(FIELD_GEOM))); } catch (IOException e) { //let it be empty geometry e.printStackTrace(); } for (int i = 0; i < mFields.size(); i++) { Field field = mFields.get(i); int index = cursor.getColumnIndex(field.getName()); if (cursor.isNull(index)) { setFieldValue(i, null); } else { if (index != NOT_FOUND) { switch (field.getType()) { case FTString: setFieldValue(i, cursor.getString(index)); break; case FTInteger: setFieldValue(i, cursor.getLong(index)); break; case FTReal: setFieldValue(i, cursor.getDouble(index)); break; case FTDate: case FTTime: case FTDateTime: TimeZone timeZone = TimeZone.getDefault(); timeZone.setRawOffset(0); // set to UTC Calendar calendar = Calendar.getInstance(timeZone); calendar.setTimeInMillis(cursor.getLong(index)); setFieldValue(i, calendar.getTimeInMillis()); break; default: break; } } } } }
Example 7
Source File: NGWVectorLayer.java From android_maplib with GNU Lesser General Public License v3.0 | 4 votes |
protected String cursorToJson(Cursor cursor) throws JSONException, IOException { JSONObject rootObject = new JSONObject(); if (0 != (mSyncType & Constants.SYNC_ATTRIBUTES)) { JSONObject valueObject = new JSONObject(); for (int i = 0; i < cursor.getColumnCount(); i++) { String name = cursor.getColumnName(i); if (name.equals(Constants.FIELD_ID) || name.equals(Constants.FIELD_GEOM)) { continue; } Field field = mFields.get(cursor.getColumnName(i)); if (null == field) { continue; } switch (field.getType()) { case GeoConstants.FTReal: valueObject.put(name, cursor.getFloat(i)); break; case GeoConstants.FTInteger: valueObject.put(name, cursor.getInt(i)); break; case GeoConstants.FTString: String stringVal = cursor.getString(i); if (null != stringVal && !stringVal.equals("null")) { valueObject.put(name, stringVal); } break; case GeoConstants.FTDateTime: TimeZone timeZoneDT = TimeZone.getDefault(); timeZoneDT.setRawOffset(0); // set to UTC Calendar calendarDT = Calendar.getInstance(timeZoneDT); calendarDT.setTimeInMillis(cursor.getLong(i)); JSONObject jsonDateTime = new JSONObject(); jsonDateTime.put("year", calendarDT.get(Calendar.YEAR)); jsonDateTime.put("month", calendarDT.get(Calendar.MONTH) + 1); jsonDateTime.put("day", calendarDT.get(Calendar.DAY_OF_MONTH)); jsonDateTime.put("hour", calendarDT.get(Calendar.HOUR_OF_DAY)); jsonDateTime.put("minute", calendarDT.get(Calendar.MINUTE)); jsonDateTime.put("second", calendarDT.get(Calendar.SECOND)); valueObject.put(name, jsonDateTime); break; case GeoConstants.FTDate: TimeZone timeZoneD = TimeZone.getDefault(); timeZoneD.setRawOffset(0); // set to UTC Calendar calendarD = Calendar.getInstance(timeZoneD); calendarD.setTimeInMillis(cursor.getLong(i)); JSONObject jsonDate = new JSONObject(); jsonDate.put("year", calendarD.get(Calendar.YEAR)); jsonDate.put("month", calendarD.get(Calendar.MONTH) + 1); jsonDate.put("day", calendarD.get(Calendar.DAY_OF_MONTH)); valueObject.put(name, jsonDate); break; case GeoConstants.FTTime: TimeZone timeZoneT = TimeZone.getDefault(); timeZoneT.setRawOffset(0); // set to UTC Calendar calendarT = Calendar.getInstance(timeZoneT); calendarT.setTimeInMillis(cursor.getLong(i)); JSONObject jsonTime = new JSONObject(); jsonTime.put("hour", calendarT.get(Calendar.HOUR_OF_DAY)); jsonTime.put("minute", calendarT.get(Calendar.MINUTE)); jsonTime.put("second", calendarT.get(Calendar.SECOND)); valueObject.put(name, jsonTime); break; default: break; } } rootObject.put(NGWUtil.NGWKEY_FIELDS, valueObject); } if (0 != (mSyncType & Constants.SYNC_GEOMETRY)) { //may be found geometry in cache by id is faster GeoGeometry geometry = GeoGeometryFactory.fromBlob( cursor.getBlob(cursor.getColumnIndex(Constants.FIELD_GEOM))); geometry.setCRS(GeoConstants.CRS_WEB_MERCATOR); if (mCRS != GeoConstants.CRS_WEB_MERCATOR) geometry.project(mCRS); rootObject.put(NGWUtil.NGWKEY_GEOM, geometry.toWKT(true)); //rootObject.put("id", cursor.getLong(cursor.getColumnIndex(FIELD_ID))); } return rootObject.toString(); }
Example 8
Source File: DateConverter.java From PdfBox-Android with Apache License 2.0 | 4 votes |
static boolean parseTZoffset(String text, GregorianCalendar cal, ParsePosition initialWhere) { ParsePosition where = new ParsePosition(initialWhere.getIndex()); TimeZone tz = new SimpleTimeZone(0, "GMT"); int tzHours, tzMin; char sign = skipOptionals(text, where, "Z+- "); boolean hadGMT = (sign == 'Z' || skipString(text, "GMT", where) || skipString(text, "UTC", where)); sign = (!hadGMT) ? sign : skipOptionals(text, where, "+- "); tzHours = parseTimeField(text, where, 2, -999); skipOptionals(text, where, "\': "); tzMin = parseTimeField(text, where, 2, 0); skipOptionals(text, where, "\' "); if (tzHours != -999) { // we parsed a time zone in default format int hrSign = (sign == '-' ? -1 : 1); tz.setRawOffset(restrainTZoffset(hrSign * (tzHours * MILLIS_PER_HOUR + tzMin * (long) MILLIS_PER_MINUTE))); tz.setID("unknown"); } else if ( ! hadGMT) { // try to process as a name; "GMT" or "UTC" has already been processed String tzText = text.substring(initialWhere.getIndex()).trim(); tz = TimeZone.getTimeZone(tzText); // getTimeZone returns "GMT" for unknown ids if ("GMT".equals(tz.getID())) { // no timezone in text, cal amd initialWhere are unchanged return false; } else { // we got a tz by name; use it where.setIndex(text.length()); } } adjustTimeZoneNicely(cal, tz); initialWhere.setIndex(where.getIndex()); return true; }