List of usage examples for java.util GregorianCalendar getTimeInMillis
public long getTimeInMillis()
From source file:org.opencms.ui.login.CmsLoginHelper.java
/** * Sets the cookie in the response.<p> * * @param cookie the cookie to set/*from w w w . j a v a2 s. c o m*/ * @param delete flag to determine if the cookir should be deleted * @param request the current request * @param response the current response */ protected static void setCookie(Cookie cookie, boolean delete, HttpServletRequest request, HttpServletResponse response) { if (request.getAttribute(PARAM_PREDEF_OUFQN) != null) { // prevent the use of cookies if using a direct ou login url return; } int maxAge = 0; if (!delete) { // set the expiration date of the cookie to six months from today GregorianCalendar cal = new GregorianCalendar(); cal.add(Calendar.MONTH, 6); maxAge = (int) ((cal.getTimeInMillis() - System.currentTimeMillis()) / 1000); } cookie.setMaxAge(maxAge); // set the path cookie.setPath(CmsStringUtil.joinPaths(OpenCms.getStaticExportManager().getVfsPrefix(), CmsWorkplaceLoginHandler.LOGIN_HANDLER)); // set the cookie response.addCookie(cookie); }
From source file:com.jmstudios.redmoon.receiver.AutomaticFilterChangeReceiver.java
public static void scheduleNextAlarm(Context context, String time, Intent operation) { GregorianCalendar calendar = new GregorianCalendar(); calendar.set(Calendar.HOUR_OF_DAY, Integer.parseInt(time.split(":")[0])); calendar.set(Calendar.MINUTE, Integer.parseInt(time.split(":")[1])); GregorianCalendar now = new GregorianCalendar(); now.add(Calendar.SECOND, 1);/* w ww.j av a2 s. c o m*/ if (calendar.before(now)) { calendar.add(Calendar.DATE, 1); } if (DEBUG) Log.i(TAG, "Scheduling alarm for " + calendar.toString()); AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, operation, 0); if (android.os.Build.VERSION.SDK_INT >= 19) { alarmManager.setExact(AlarmManager.RTC, calendar.getTimeInMillis(), pendingIntent); } else { alarmManager.set(AlarmManager.RTC, calendar.getTimeInMillis(), pendingIntent); } }
From source file:org.oscarehr.common.hl7.v2.oscar_to_oscar.DataTypeUtils.java
private static GregorianCalendar getCalendarFromDT(DT dt) throws DataTypeException { // hl7/hapi returns 0 for no date if (dt.getYear() == 0 || dt.getMonth() == 0 || dt.getDay() == 0) return (null); GregorianCalendar cal = new GregorianCalendar(); // zero out fields we don't use cal.setTimeInMillis(0);/*from ww w. j a va 2 s.com*/ cal.set(GregorianCalendar.YEAR, dt.getYear()); cal.set(GregorianCalendar.MONTH, dt.getMonth() - 1); cal.set(GregorianCalendar.DAY_OF_MONTH, dt.getDay()); // force materialisation of values cal.getTimeInMillis(); return (cal); }
From source file:fr.ippon.wip.ltpa.token.LtpaLibrary.java
/** * Create a valid LTPA token for the specified user. * * @param username - the user to create the LTPA token for. * @param creationTime - the time the token becomes valid. * @param durationMinutes - the duration of the token validity in minutes. * @param ltpaSecretStr - the LTPA Domino Secret to use to create the token. * @return - base64 encoded LTPA token, ready for the cookie. * @throws NoSuchAlgorithmException/*from w w w . java2s.c om*/ */ public static String createLtpaToken(String username, GregorianCalendar creationTime, int durationMinutes, String ltpaSecretStr) throws NoSuchAlgorithmException { // create byte array buffers for both strings byte[] ltpaSecret = Base64.decodeBase64(ltpaSecretStr.getBytes()); byte[] usernameArray = username.getBytes(); byte[] workingBuffer = new byte[preUserDataLength + usernameArray.length + ltpaSecret.length]; // copy version into workingBuffer System.arraycopy(ltpaTokenVersion, 0, workingBuffer, 0, ltpaTokenVersion.length); GregorianCalendar expirationDate = (GregorianCalendar) creationTime.clone(); expirationDate.add(Calendar.MINUTE, durationMinutes); // copy creation date into workingBuffer String hex = dateStringFiller + Integer.toHexString((int) (creationTime.getTimeInMillis() / 1000)).toUpperCase(); System.arraycopy(hex.getBytes(), hex.getBytes().length - dateStringLength, workingBuffer, creationDatePosition, dateStringLength); // copy expiration date into workingBuffer hex = dateStringFiller + Integer.toHexString((int) (expirationDate.getTimeInMillis() / 1000)).toUpperCase(); System.arraycopy(hex.getBytes(), hex.getBytes().length - dateStringLength, workingBuffer, expirationDatePosition, dateStringLength); // copy user name into workingBuffer System.arraycopy(usernameArray, 0, workingBuffer, preUserDataLength, usernameArray.length); // copy the ltpaSecret into the workingBuffer System.arraycopy(ltpaSecret, 0, workingBuffer, preUserDataLength + usernameArray.length, ltpaSecret.length); byte[] hash = createHash(workingBuffer); // put the public data and the hash into the outputBuffer byte[] outputBuffer = new byte[preUserDataLength + usernameArray.length + hashLength]; System.arraycopy(workingBuffer, 0, outputBuffer, 0, preUserDataLength + usernameArray.length); System.arraycopy(hash, 0, outputBuffer, preUserDataLength + usernameArray.length, hashLength); return new String(Base64.encodeBase64(outputBuffer)); }
From source file:org.apache.fontbox.ttf.TTFSubFont.java
private static void writeLongDateTime(DataOutputStream dos, Calendar calendar) throws IOException { // inverse operation of TTFDataStream.readInternationalDate() GregorianCalendar cal = new GregorianCalendar(1904, 0, 1); long millisFor1904 = cal.getTimeInMillis(); long secondsSince1904 = (calendar.getTimeInMillis() - millisFor1904) / 1000L; dos.writeLong(secondsSince1904);/*from w w w. j a v a 2 s .c o m*/ }
From source file:com.controlj.addon.weather.wbug.service.WeatherBugDataUtils.java
/** * Extracts a timestamp from a XML element. * //from w ww. j ava 2 s. c o m * @param elem * the element from which the timestamp must be extracted. * @param path * the XPath to be used to locate the value. * @return the extracted timestamp. */ public static Timestamp getTimestamp(Element elem, String path) { Element timestampElem = (Element) elem.selectSingleNode(path); final String tz = WeatherBugDataUtils.getString(timestampElem, "aws:time-zone/@abbrv") != null ? WeatherBugDataUtils.getString(timestampElem, "aws:time-zone/@abbrv") : "CST"; final GregorianCalendar cal = new GregorianCalendar(TimeZone.getTimeZone(tz)); cal.set(Calendar.YEAR, WeatherBugDataUtils.getInt(timestampElem, "aws:year/@number", -1)); cal.set(Calendar.MONTH, WeatherBugDataUtils.getInt(timestampElem, "aws:month/@number", -1) - 1); //zero based in GregorianCal cal.set(Calendar.DAY_OF_MONTH, WeatherBugDataUtils.getInt(timestampElem, "aws:day/@number", -1)); cal.set(Calendar.HOUR_OF_DAY, WeatherBugDataUtils.getInt(timestampElem, "aws:hour/@hour-24", -1)); cal.set(Calendar.MINUTE, WeatherBugDataUtils.getInt(timestampElem, "aws:minute/@number", 0)); cal.set(Calendar.SECOND, WeatherBugDataUtils.getInt(timestampElem, "aws:second/@number", 0)); cal.set(Calendar.MILLISECOND, 0); return new Timestamp(cal.getTimeInMillis()); }
From source file:org.nex.util.DateUtil.java
/** * <code>timestamp</code> looks like 2013-11-26 11:09:47.403 * @param timestamp/*from www. j a v a2s .c om*/ * @return */ public static Date fromDefaultTimestamp(String timestamp) { System.out.println("DateUtil.fromDefaultTimestamp- " + timestamp); Date result = null; String[] parts = timestamp.split(" "); String big = parts[0]; String small = parts[1]; GregorianCalendar c = new GregorianCalendar(); String[] bigger = big.split("-"); int yr = Integer.parseInt(bigger[0]); int mo = Integer.parseInt(bigger[1]); int da = Integer.parseInt(bigger[2]); String[] smaller = small.split(":"); int hr = Integer.parseInt(smaller[0]); int min = Integer.parseInt(smaller[1]); String x = smaller[2]; int where = x.indexOf('.'); if (where > -1) x = x.substring(0, where); int sec = Integer.parseInt(x); c.set(yr, mo, da, hr, min, sec); result = new Date(c.getTimeInMillis()); return result; }
From source file:org.oscarehr.common.hl7.v2.oscar_to_oscar.DataTypeUtils.java
public static GregorianCalendar getCalendarFromDTM(DTM dtm) throws DataTypeException { // hl7/hapi returns 0 for no date if (dtm.getYear() == 0 || dtm.getMonth() == 0 || dtm.getDay() == 0) return (null); GregorianCalendar cal = new GregorianCalendar(); // zero out fields we don't use cal.setTimeInMillis(0);//from ww w. j a v a2 s. com cal.set(GregorianCalendar.YEAR, dtm.getYear()); cal.set(GregorianCalendar.MONTH, dtm.getMonth() - 1); cal.set(GregorianCalendar.DAY_OF_MONTH, dtm.getDay()); cal.set(GregorianCalendar.HOUR_OF_DAY, dtm.getHour()); cal.set(GregorianCalendar.MINUTE, dtm.getMinute()); cal.set(GregorianCalendar.SECOND, dtm.getSecond()); // force materialisation of values cal.getTimeInMillis(); return (cal); }
From source file:PedidoDAO.java
@Override public Pedido consulta(String idCliente, GregorianCalendar fPedido) { Date fecha = new Date(fPedido.getTimeInMillis()); String selQuery = "select * from TPedidos where idCliente = ? and FHPedido = ?"; Pedido p = (Pedido) jdbcTemplate.queryForObject(selQuery, new Object[] { idCliente, fecha }, new PedidoMapper()); selQuery = "select * from TPedidoLineas L, TProductos P where L.idProducto = P.idProducto and idPedido = ?"; ArrayList<PedidoLinea> pl = (ArrayList<PedidoLinea>) jdbcTemplate.query(selQuery, new Object[] { p.getIdPedido() }, new BeanPropertyRowMapper(PedidoLinea.class)); p.setLineasPedido(pl);//from w ww . j ava 2s . com return p; }
From source file:de.ribeiro.android.gso.core.UntisProvider.java
/** * Ldt die Selectoren(wochen/elemente/typen) von der GSO Seite und parsed * diese in den StupidCore/*from w w w. j av a 2s .co m*/ * * @param logger * @param htmlResponse * @param getProfil () * @throws Exception * @author Tobias Janssen */ public static void syncTypeList(HtmlResponse htmlResponse, Profil mProfil) throws Exception { JSONArray clsarray = null; JSONArray teacherarray = null; JSONArray roomarray = null; GregorianCalendar date = new GregorianCalendar(); // session erzeugen und cookies abholen //TODO: Remove hardcoded URL String url = "https://webuntis.stadt-koeln.de/WebUntis/Timetable.do?request.preventCache=" + date.getTimeInMillis() + "&school=K175055"; HttpSession session = new HttpSession(url + 1); //5 Wochen in die Zukunft schauen for (int i = 0; i < 5; i++) { try { if (clsarray == null && (clsarray = RequestUrl(session, url, "1")) == null) { date.setTimeInMillis(date.getTimeInMillis() + (1000 * 60 * 60 * 24 * 7)); session.SetStupidServerDate(date, i + 1); continue; } if (teacherarray == null && (teacherarray = RequestUrl(session, url, "2")) == null) { date.setTimeInMillis(date.getTimeInMillis() + (1000 * 60 * 60 * 24 * 7)); session.SetStupidServerDate(date, i + 1); continue; } if (roomarray == null && (roomarray = RequestUrl(session, url, "4")) == null) { date.setTimeInMillis(date.getTimeInMillis() + (1000 * 60 * 60 * 24 * 7)); session.SetStupidServerDate(date, i + 1); continue; } session.Close(); _logger.Info("new Elements downloaded!"); mProfil.types.htmlModDate = htmlResponse.lastModified; break; } catch (Exception e) { throw new SyncFailedException(e.getMessage()); } } Type type = new Type(); type.elementList = ConvertJSonArray(clsarray); type.typeName = "Klassen"; type.type = "1"; AddTypeToProfil(mProfil, type); type = new Type(); type.elementList = ConvertJSonArray(teacherarray); type.typeName = "Lehrer"; type.type = "2"; AddTypeToProfil(mProfil, type); type = new Type(); type.elementList = ConvertJSonArray(roomarray); type.typeName = "Rume"; type.type = "4"; AddTypeToProfil(mProfil, type); mProfil.isDirty = true; }