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:net.maritimecloud.identityregistry.controllers.BaseControllerWithCertificate.java
protected PemCertificate issueCertificate(CertificateModel certOwner, Organization org, String type, HttpServletRequest request) throws McBasicRestException { // Generate keypair for user KeyPair userKeyPair = CertificateUtil.generateKeyPair(); // Find special MC attributes to put in the certificate HashMap<String, String> attrs = getAttr(certOwner); String o = org.getMrn();// w ww. j av a2s .c om String name = getName(certOwner); String email = getEmail(certOwner); String uid = getUid(certOwner); if (uid == null || uid.trim().isEmpty()) { throw new McBasicRestException(HttpStatus.BAD_REQUEST, MCIdRegConstants.ENTITY_ORG_ID_MISSING, request.getServletPath()); } BigInteger serialNumber = certUtil.generateSerialNumber(); X509Certificate userCert = certUtil.generateCertForEntity(serialNumber, org.getCountry(), o, type, name, email, uid, userKeyPair.getPublic(), attrs); String pemCertificate; try { pemCertificate = CertificateUtil.getPemFromEncoded("CERTIFICATE", userCert.getEncoded()).replace("\n", "\\n"); } catch (CertificateEncodingException e) { throw new RuntimeException(e.getMessage(), e); } String pemPublicKey = CertificateUtil.getPemFromEncoded("PUBLIC KEY", userKeyPair.getPublic().getEncoded()) .replace("\n", "\\n"); String pemPrivateKey = CertificateUtil .getPemFromEncoded("PRIVATE KEY", userKeyPair.getPrivate().getEncoded()).replace("\n", "\\n"); PemCertificate ret = new PemCertificate(pemPrivateKey, pemPublicKey, pemCertificate); // Create the certificate Certificate newMCCert = new Certificate(); certOwner.assignToCert(newMCCert); newMCCert.setCertificate(pemCertificate); newMCCert.setSerialNumber(serialNumber); // The dates we extract from the cert is in localtime, so they are converted to UTC before saving into the DB Calendar cal = Calendar.getInstance(); long offset = cal.get(Calendar.ZONE_OFFSET) + cal.get(Calendar.DST_OFFSET); newMCCert.setStart(new Date(userCert.getNotBefore().getTime() - offset)); newMCCert.setEnd(new Date(userCert.getNotAfter().getTime() - offset)); this.certificateService.saveCertificate(newMCCert); return ret; }
From source file:edu.harvard.i2b2.query.data.QueryConceptTreePanelData.java
public ConstrainByDate writeTimeConstraint() { ConstrainByDate timeConstrain = new ConstrainByDate(); DTOFactory dtoFactory = new DTOFactory(); TimeZone tz = Calendar.getInstance().getTimeZone(); GregorianCalendar cal = new GregorianCalendar(tz); //cal.get(Calendar.ZONE_OFFSET); int zt_offset = (cal.get(Calendar.ZONE_OFFSET) + cal.get(Calendar.DST_OFFSET)) / 60000; log.info("Timezone: " + tz.getID() + " : " + zt_offset); if (startTime() != -1) { ConstrainDateType constraindateType = new ConstrainDateType(); XMLGregorianCalendar xmlC = dtoFactory.getXMLGregorianCalendarDate(startYear(), startMonth() + 1, startDay());/*from w w w . j a v a 2s .c o m*/ xmlC.setTimezone(zt_offset);//0);//-5*60); xmlC.setHour(0); xmlC.setMinute(0); xmlC.setSecond(0); constraindateType.setValue(xmlC); timeConstrain.setDateFrom(constraindateType); } if (endTime() != -1) { ConstrainDateType constraindateType = new ConstrainDateType(); XMLGregorianCalendar xmlC = dtoFactory.getXMLGregorianCalendarDate(endYear(), endMonth() + 1, endDay()); xmlC.setTimezone(zt_offset);//0);//-5*60); xmlC.setHour(0); xmlC.setMinute(0); xmlC.setSecond(0); constraindateType.setValue(xmlC); timeConstrain.setDateTo(constraindateType); } return timeConstrain; }
From source file:org.programmatori.domotica.own.plugin.system.System.java
private SCSMsg setTime(SCSMsg msg) { Calendar newTime = GregorianCalendar.getInstance(); newTime.set(Calendar.HOUR_OF_DAY, msg.getProperty().getMain()); newTime.set(Calendar.MINUTE, Integer.parseInt(msg.getProperty().getParams(0))); newTime.set(Calendar.SECOND, Integer.parseInt(msg.getProperty().getParams(1))); newTime.set(Calendar.ZONE_OFFSET, Integer.parseInt(msg.getProperty().getParams(2))); Config.getInstance().setUserTime(newTime); return SCSMsg.MSG_ACK; }
From source file:org.openbravo.client.kernel.reference.TimeUIDefinition.java
private StringBuffer convertUtcToLocalTime(String value) { StringBuffer localTimeColumnValue = null; try {/*from w w w . j av a2 s . co m*/ Date UTCDate = getClassicFormat().parse(value); Calendar now = Calendar.getInstance(); Calendar calendar = Calendar.getInstance(); calendar.setTime(UTCDate); 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); localTimeColumnValue = getClassicFormat().format(calendar.getTime(), new StringBuffer(), new FieldPosition(0)); } catch (ParseException e) { throw new OBException("Exception when parsing date ", e); } return localTimeColumnValue; }
From source file:ISO8601DateTimeFormat.java
/** * Parse the time zone./*from www. j a va 2 s. co m*/ * @param i The position to start parsing. * @param text The text to parse. * @return The position after parsing has finished. */ protected final int parseTZ(int i, String text) { if (i < text.length()) { // check and handle the zone/dst offset int offset = 0; if (text.charAt(i) == 'Z') { offset = 0; i++; } else { int sign = 1; if (text.charAt(i) == '-') { sign = -1; } else if (text.charAt(i) != '+') { throw new NumberFormatException(); } i++; int offsetHour = Integer.valueOf(text.substring(i, i + 2)).intValue(); i += 2; if (text.charAt(i) != ':') { throw new NumberFormatException(); } i++; int offsetMin = Integer.valueOf(text.substring(i, i + 2)).intValue(); i += 2; offset = ((offsetHour * 60) + offsetMin) * 60000 * sign; } int offsetCal = calendar.get(Calendar.ZONE_OFFSET) + calendar.get(Calendar.DST_OFFSET); calendar.add(Calendar.MILLISECOND, offsetCal - offset); } return i; }
From source file:org.mariotaku.twidere.api.twitter.util.TwitterDateConverter.java
@Override public String convertToString(Date date) { final Calendar calendar = Calendar.getInstance(); calendar.setTime(date);/*from w ww . j a v a2 s. c om*/ final StringBuilder sb = new StringBuilder(); sb.append(WEEK_NAMES[calendar.get(Calendar.DAY_OF_WEEK) - 1]); sb.append(' '); sb.append(MONTH_NAMES[calendar.get(Calendar.MONTH)]); sb.append(' '); sb.append(calendar.get(Calendar.DAY_OF_MONTH)); sb.append(' '); sb.append(calendar.get(Calendar.HOUR_OF_DAY)); sb.append(':'); sb.append(calendar.get(Calendar.MINUTE)); sb.append(':'); sb.append(calendar.get(Calendar.SECOND)); sb.append(' '); final long offset = TimeUnit.MILLISECONDS.toMinutes(calendar.get(Calendar.ZONE_OFFSET)); sb.append(offset > 0 ? '+' : '-'); sb.append(String.format(Locale.ROOT, "%02d%02d", Math.abs(offset) / 60, Math.abs(offset) % 60)); sb.append(' '); sb.append(calendar.get(Calendar.YEAR)); return sb.toString(); }
From source file:org.hyperic.snmp.SNMPValue.java
private long convertDateAndTimeToLong() throws SNMPException { byte[] bytes = getBytes(); if (bytes.length < 8) { String msg = "OctetString is not in DateAndTime syntax"; throw new SNMPException(msg); }//from w w w . j a v a 2 s . c o m Calendar cal = Calendar.getInstance(); int ix = 0; int year = (bytes[ix] > 0) ? bytes[ix] : (256 + bytes[ix]); year <<= 8; ix++; year += (bytes[ix] > 0) ? bytes[ix] : (256 + bytes[ix]); ix++; int month = bytes[ix++]; int day = bytes[ix++]; int hour = bytes[ix++]; int minutes = bytes[ix++]; int seconds = bytes[ix++]; int deciseconds = bytes[ix++]; cal.set(Calendar.YEAR, year); cal.set(Calendar.MONTH, (month - 1)); cal.set(Calendar.DAY_OF_MONTH, day); cal.set(Calendar.HOUR_OF_DAY, hour); cal.set(Calendar.MINUTE, minutes); cal.set(Calendar.SECOND, seconds); cal.set(Calendar.MILLISECOND, (100 * deciseconds)); cal.set(Calendar.ZONE_OFFSET, 0); cal.set(Calendar.DST_OFFSET, 0); if (log.isDebugEnabled()) { log.debug("converted to DateAndTime: millis=" + cal.getTimeInMillis() + ", date=" + cal.getTime()); } return cal.getTimeInMillis(); }
From source file:org.rhq.plugins.www.snmp.SNMPValue.java
private long convertDateTimeOctetStringToLong() throws SNMPException { byte[] bytes = ((OctetString) this.var).getValue(); if (bytes.length != 8) { throw new SNMPException("OctetString is not in DateAndTime syntax."); }/*from w ww . ja va 2 s . c o m*/ Calendar cal = Calendar.getInstance(); int ix = 0; int year = (bytes[ix] > 0) ? bytes[ix] : (256 + bytes[ix]); year <<= 8; ix++; year += (bytes[ix] > 0) ? bytes[ix] : (256 + bytes[ix]); ix++; int month = bytes[ix++]; int day = bytes[ix++]; int hour = bytes[ix++]; int minutes = bytes[ix++]; int seconds = bytes[ix++]; int deciseconds = bytes[ix++]; cal.set(Calendar.YEAR, year); cal.set(Calendar.MONTH, (month - 1)); cal.set(Calendar.DAY_OF_MONTH, day); cal.set(Calendar.HOUR_OF_DAY, hour); cal.set(Calendar.MINUTE, minutes); cal.set(Calendar.SECOND, seconds); cal.set(Calendar.MILLISECOND, (100 * deciseconds)); cal.set(Calendar.ZONE_OFFSET, 0); cal.set(Calendar.DST_OFFSET, 0); if (log.isDebugEnabled()) { log.debug("converted to DateAndTime: millis=" + cal.getTimeInMillis() + ", date=" + cal.getTime()); } return cal.getTimeInMillis(); }
From source file:org.eclipse.smila.ontology.records.SesameValueHelper.java
/** * create a Sesame date/time literal value from a SMILA date/time value. * /*w w w .ja va2 s .com*/ * @param connection * repository connection * @param literal * a SMILA literal with a date/time value. * @return a Sesame date/time literal, if all goes well. Else return a string literal as fallback. */ private org.openrdf.model.Literal createDateTimeLiteral(final RepositoryConnection connection, final Value literal) { try { final DatatypeFactory factory = DatatypeFactory.newInstance(); final Calendar cal = Calendar.getInstance(); cal.setTime(literal.asDateTime()); final int zoneOffsetMinutes = cal.get(Calendar.ZONE_OFFSET) / MILLISECONDS_PER_MINUTE; final XMLGregorianCalendar time = factory.newXMLGregorianCalendar(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH) + 1, cal.get(Calendar.DAY_OF_MONTH), cal.get(Calendar.HOUR_OF_DAY), cal.get(Calendar.MINUTE), cal.get(Calendar.SECOND), cal.get(Calendar.MILLISECOND), zoneOffsetMinutes); return connection.getValueFactory().createLiteral(time); } catch (final Exception ex) { _log.warn("cuold not create a time literal from value '" + literal + "', just adding a string literal", ex); return connection.getValueFactory().createLiteral(literal.toString()); } }
From source file:ch.ethz.dcg.jukefox.model.player.playlog.PlayLog.java
License:asdf
public void writeToPlayLog(final Date time, final PlaylistSong<BaseArtist, BaseAlbum> song, final boolean skip, final int playbackPosition) { int day_of_week = 0, hour_of_day = 0; long utcTime = time.getTime(); Calendar cal = Calendar.getInstance(); // in minutes int timeZoneOffset = (cal.get(Calendar.ZONE_OFFSET) + cal.get(Calendar.DST_OFFSET)) / 60000; // in hours//www.j a v a2 s . c o m timeZoneOffset /= 60; Calendar logcalendar = Calendar.getInstance(); logcalendar.setTimeInMillis(time.getTime()); day_of_week = logcalendar.get(Calendar.DAY_OF_WEEK); hour_of_day = logcalendar.get(Calendar.HOUR_OF_DAY); Log.v(TAG, "day of week: " + day_of_week); Log.v(TAG, "hour of day: " + hour_of_day); Log.v(TAG, "utcTime: " + utcTime); AbstractContextResult contextData = contextProvider.getMeanContextValues(30 * 1000); try { // Write playlog entry dbDataPortal.writePlayLogEntry(playerModelId, song, utcTime, timeZoneOffset, day_of_week, hour_of_day, skip, playerController.getPlayMode().getPlayModeType().value(), contextData, playbackPosition); // Write a rating entry as well double fractionPlayed = playbackPosition / (double) song.getDuration(); ratingHelper.addRatingFromPlayLog(song, time, fractionPlayed); } catch (DataWriteException e) { Log.w(TAG, e); } }