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.appverse.web.framework.backend.frontfacade.json.controllers.JSONDateSerializer.java
@Override public void serialize(Date date, JsonGenerator gen, SerializerProvider provider) throws IOException, JsonProcessingException { long millis = date.getTime(); Date currentDate = new Date(); Calendar cal = new GregorianCalendar(); cal.setTime(currentDate);//from w w w . j a va 2s .co m int offset = cal.get(Calendar.ZONE_OFFSET) + cal.get(Calendar.DST_OFFSET); gen.writeNumber(millis + offset); }
From source file:CalendarDemo.java
public void format() { // Tell the calendar what date/time to format calendar.setTime(timeNow);/*from w w w .j ava2 s .co m*/ // print out most of the known fields System.out.println("ERA: " + calendar.get(Calendar.ERA)); System.out.println("YEAR: " + calendar.get(Calendar.YEAR)); System.out.println("MONTH: " + calendar.get(Calendar.MONTH)); System.out.println("WEEK_OF_YEAR: " + calendar.get(Calendar.WEEK_OF_YEAR)); System.out.println("WEEK_OF_MONTH: " + calendar.get(Calendar.WEEK_OF_MONTH)); System.out.println("DATE: " + calendar.get(Calendar.DATE)); System.out.println("DAY_OF_MONTH: " + calendar.get(Calendar.DAY_OF_MONTH)); System.out.println("DAY_OF_YEAR: " + calendar.get(Calendar.DAY_OF_YEAR)); System.out.println("DAY_OF_WEEK: " + calendar.get(Calendar.DAY_OF_WEEK)); System.out.println("DAY_OF_WEEK_IN_MONTH: " + calendar.get(Calendar.DAY_OF_WEEK_IN_MONTH)); System.out.println("AM_PM: " + calendar.get(Calendar.AM_PM)); System.out.println("HOUR: " + calendar.get(Calendar.HOUR)); System.out.println("HOUR_OF_DAY: " + calendar.get(Calendar.HOUR_OF_DAY)); System.out.println("MINUTE: " + calendar.get(Calendar.MINUTE)); System.out.println("SECOND: " + calendar.get(Calendar.SECOND)); System.out.println("MILLISECOND: " + calendar.get(Calendar.MILLISECOND)); System.out.println("ZONE_OFFSET: " + (calendar.get(Calendar.ZONE_OFFSET) / (60 * 60 * 1000))); System.out.println("DST_OFFSET: " + (calendar.get(Calendar.DST_OFFSET) / (60 * 60 * 1000))); }
From source file:com.balch.mocktrade.finance.QuoteGoogleFinance.java
@Override public Date getLastTradeTime() { TimeZone ny_tz = TimeZone.getTimeZone("America/New_York"); Calendar ny_cal = Calendar.getInstance(ny_tz); int offset_mins = (ny_cal.get(Calendar.ZONE_OFFSET) + ny_cal.get(Calendar.DST_OFFSET)) / 60000; String dateStr = this.data.get(LastTradeTime); dateStr = dateStr.replace("Z", String.format("%s%02d:%02d", (offset_mins >= 0) ? "+" : "-", Math.abs(offset_mins / 60), Math.abs(offset_mins % 60))); try {//www.jav a2 s.c o m return ISO8601DateTime.toDate(dateStr); } catch (ParseException e) { Log.e(TAG, "Error parsing date:" + dateStr, e); throw new RuntimeException(e); } }
From source file:com.alibaba.ims.platform.util.DateUtil.java
/** * ?UTC/*from w ww. j a v a 2 s . com*/ * * @return */ public static long getUTCTimeInMillis() { Calendar cal = Calendar.getInstance(); return cal.getTimeInMillis() - cal.get(Calendar.ZONE_OFFSET); }
From source file:com.mi.xserv.XservBase.java
protected int getTimeZoneOffset() { // GMT es. italia +1 TimeZone timezone = TimeZone.getDefault(); int seconds = timezone.getOffset(Calendar.ZONE_OFFSET) / 1000; double minutes = seconds / 60; double hours = minutes / 60; return (int) hours; }
From source file:org.mule.el.datetime.AbstractInstant.java
private int getTimeZoneOffset() { return calendar.get(Calendar.ZONE_OFFSET); }
From source file:org.mariotaku.twidere.api.twitter.util.TwitterDateConverter.java
private Date parseTwitterDate(String string) { final String[] segs = StringUtils.split(string, ' '); if (segs.length != 6) { return null; }//from w w w . j a v a 2s. co m final String[] timeSegs = StringUtils.split(segs[3], ':'); if (timeSegs.length != 3) { return null; } final GregorianCalendar calendar = new GregorianCalendar(TIME_ZONE, LOCALE); calendar.clear(); final int monthIdx = ArrayUtils.indexOf(MONTH_NAMES, segs[1]); if (monthIdx < 0) { return null; } calendar.set(Calendar.YEAR, Integer.parseInt(segs[5])); calendar.set(Calendar.MONTH, monthIdx); calendar.set(Calendar.DAY_OF_MONTH, Integer.parseInt(segs[2])); calendar.set(Calendar.HOUR_OF_DAY, Integer.parseInt(timeSegs[0])); calendar.set(Calendar.MINUTE, Integer.parseInt(timeSegs[1])); calendar.set(Calendar.SECOND, Integer.parseInt(timeSegs[2])); calendar.set(Calendar.ZONE_OFFSET, SimpleTimeZone.getTimeZone("GMT" + segs[4]).getRawOffset()); final Date date = calendar.getTime(); if (!WEEK_NAMES[calendar.get(Calendar.DAY_OF_WEEK) - 1].equals(segs[0])) { AbsLogger.error("Week mismatch " + string + " => " + date); return null; } return date; }
From source file:org.kuali.coeus.s2sgen.impl.datetime.S2SDateTimeServiceImpl.java
public String removeTimezoneFactor(String applicationXmlText, Calendar cal) { int zoneOffsetMilli = cal.get(Calendar.ZONE_OFFSET); int zoneOffsetNow = zoneOffsetMilli / (1000 * 60 * 60); int zoneOffsetDST = zoneOffsetMilli / (1000 * 60 * 60) + 1; String timezoneIdNow = TimeZone.getTimeZone("GMT" + zoneOffsetNow).getID(); String timezoneIdDst = TimeZone.getTimeZone("GMT" + zoneOffsetDST).getID(); String offset = "+00:00"; if (timezoneIdNow.length() > 6) { offset = timezoneIdNow.substring(timezoneIdNow.length() - 6); applicationXmlText = StringUtils.remove(applicationXmlText, offset); }/*from www .j a v a 2s.c o m*/ if (timezoneIdDst.length() > 6) { offset = timezoneIdDst.substring(timezoneIdDst.length() - 6); applicationXmlText = StringUtils.remove(applicationXmlText, offset); } return applicationXmlText; }
From source file:org.opencastproject.capture.impl.ConfigurationManager.java
private void updateTimezone(XProperties properties) { Calendar cal = Calendar.getInstance(); properties.setProperty("capture.device.timezone.offset", Long.toString((cal.get(Calendar.ZONE_OFFSET) + cal.get(Calendar.DST_OFFSET)) / (1 * CaptureParameters.MINUTES * CaptureParameters.MILLISECONDS))); properties.setProperty("capture.device.timezone", TimeZone.getDefault().getID()); }
From source file:foam.uavtoolkit.starwisp.java
/** Called when the activity is first created. */ @Override/* ww w. ja va 2s.co m*/ public void onCreate(Bundle savedInstanceState) { String dirname = "uavtoolkit/"; m_AppDir = "/sdcard/" + dirname; File appdir = new File(m_AppDir); appdir.mkdirs(); File filesdir = new File(m_AppDir + "/files/"); filesdir.mkdirs(); File backupdir = new File(m_AppDir + "/backup/"); backupdir.mkdirs(); // build static things m_Scheme = new Scheme(this); m_Scheme.Load("lib.scm"); m_Scheme.Load("json.scm"); m_Scheme.Load("racket-fix.scm"); m_Scheme.Load("eavdb/ktv.ss"); m_Scheme.Load("eavdb/ktv-list.ss"); m_Scheme.Load("eavdb/entity-values.ss"); m_Scheme.Load("eavdb/entity-insert.ss"); m_Scheme.Load("eavdb/entity-get.ss"); m_Scheme.Load("eavdb/entity-update.ss"); m_Scheme.Load("eavdb/entity-filter.ss"); m_Scheme.Load("eavdb/entity-sync.ss"); m_Scheme.Load("eavdb/entity-csv.ss"); m_Scheme.Load("eavdb/eavdb.ss"); m_Scheme.Load("dbsync.scm"); m_Builder = new StarwispBuilder(m_Scheme); m_Name = "main"; // tell scheme the date final Calendar c = Calendar.getInstance(); int day = c.get(Calendar.DAY_OF_MONTH); int month = c.get(Calendar.MONTH) + 1; int year = c.get(Calendar.YEAR); int timezone_offset_mins = (c.get(Calendar.ZONE_OFFSET) + c.get(Calendar.DST_OFFSET)) / 60000; String version = "Version not found"; try { PackageInfo pInfo = getPackageManager().getPackageInfo(getPackageName(), 0); version = pInfo.versionName; } catch (NameNotFoundException e) { Log.e("starwisp", "Error getting version " + e.toString()); } // pass in a bunch of useful stuff m_Scheme.eval("(define dirname \"/sdcard/" + dirname + "\")" + "(define date-day " + day + ")" + "(define date-month " + month + ")" + "(define date-year " + year + ")" + "(define timezone-offset-mins " + timezone_offset_mins + ")" + "(define app-version " + version + ")"); // pass in a bunch of useful stuff DeclareSensors(); m_Scheme.Load("review-data.scm"); m_Scheme.Load("uav-toolkit.scm"); Log.i("starwisp", "started, now running starwisp.scm..."); m_Scheme.eval(m_Scheme.readRawTextFile(this, "translations.scm")); m_Scheme.eval(m_Scheme.readRawTextFile(this, "starwisp.scm")); super.onCreate(savedInstanceState); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); }