List of usage examples for java.util Calendar getTimeInMillis
public long getTimeInMillis()
From source file:com.esri.cordova.geolocation.utils.JSONHelper.java
/** * Converts CellInfoCdma into JSON//from w ww . j a v a 2 s. c om * @param cellInfo CellInfoCdma * @return JSON */ public static String cellInfoCDMAJSON(CellInfoCdma cellInfo, boolean returnSignalStrength) { final Calendar calendar = Calendar.getInstance(); final JSONObject json = new JSONObject(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2 && cellInfo != null) { try { json.put("provider", CELLINFO_PROVIDER); json.put("type", CDMA); json.put("timestamp", calendar.getTimeInMillis()); final CellIdentityCdma identityCdma = cellInfo.getCellIdentity(); json.put("latitude", CdmaCellLocation.convertQuartSecToDecDegrees(identityCdma.getLatitude())); json.put("longitude", CdmaCellLocation.convertQuartSecToDecDegrees(identityCdma.getLongitude())); json.put("basestationId", identityCdma.getBasestationId()); json.put("networkId", identityCdma.getNetworkId()); json.put("systemId", identityCdma.getSystemId()); if (returnSignalStrength) { final JSONObject jsonSignalStrength = new JSONObject(); final CellSignalStrengthCdma cellSignalStrengthCdma = cellInfo.getCellSignalStrength(); jsonSignalStrength.put("asuLevel", cellSignalStrengthCdma.getAsuLevel()); jsonSignalStrength.put("cdmaDbm", cellSignalStrengthCdma.getCdmaDbm()); jsonSignalStrength.put("cdmaEcio", cellSignalStrengthCdma.getCdmaEcio()); jsonSignalStrength.put("cdmaLevel", cellSignalStrengthCdma.getCdmaLevel()); jsonSignalStrength.put("dbm", cellSignalStrengthCdma.getDbm()); jsonSignalStrength.put("evdoDbm", cellSignalStrengthCdma.getEvdoDbm()); jsonSignalStrength.put("evdoEcio", cellSignalStrengthCdma.getEvdoEcio()); jsonSignalStrength.put("evdoLevel", cellSignalStrengthCdma.getEvdoLevel()); jsonSignalStrength.put("evdoSnr", cellSignalStrengthCdma.getEvdoSnr()); jsonSignalStrength.put("level", cellSignalStrengthCdma.getLevel()); json.put("cellSignalStrengthCdma", jsonSignalStrength); } } catch (JSONException exc) { logJSONException(exc); } } return json.toString(); }
From source file:ips1ap101.lib.base.util.TimeUtils.java
public static java.util.Date parse(String pdq) { String string = pdq == null ? null : pdq.toString().trim(); if (string == null || string.isEmpty()) { return null; }/* w w w . j ava 2s . co m*/ int year = 1970; int monthOfYear = 1; int dayOfMonth = 1; int hourOfDay = 0; int minuteOfHour = 0; int secondOfMinute = 0; String xm = ""; String xs = ""; String format = getDateFormat(); int len = string.length(); switch (len) { case 22: xm = string.substring(20); case 19: if (xm.isEmpty()) { xs = string.substring(17, 19); } if (xs.equalsIgnoreCase("AM") || xs.equalsIgnoreCase("PM")) { xm = xs; } else { secondOfMinute = Integer.parseInt(string.substring(17, 19)); } case 16: minuteOfHour = Integer.parseInt(string.substring(14, 16)); hourOfDay = Integer.parseInt(string.substring(11, 13)); if (xm.equalsIgnoreCase("AM") && hourOfDay == 12) { hourOfDay = 0; } if (xm.equalsIgnoreCase("PM") && hourOfDay <= 11) { hourOfDay += 12; } format = getTimestampFormat(); case 10: switch (format.substring(0, 2)) { case "yy": year = Integer.parseInt(string.substring(0, 4)); monthOfYear = Integer.parseInt(string.substring(5, 7)); dayOfMonth = Integer.parseInt(string.substring(8, 10)); break; case "MM": year = Integer.parseInt(string.substring(6, 10)); monthOfYear = Integer.parseInt(string.substring(0, 2)); dayOfMonth = Integer.parseInt(string.substring(3, 5)); break; case "dd": default: year = Integer.parseInt(string.substring(6, 10)); monthOfYear = Integer.parseInt(string.substring(3, 5)); dayOfMonth = Integer.parseInt(string.substring(0, 2)); break; } break; case 8: xm = string.substring(6); case 6: minuteOfHour = Integer.parseInt(string.substring(3, 5)); hourOfDay = Integer.parseInt(string.substring(0, 2)); if (xm.equalsIgnoreCase("AM") && hourOfDay == 12) { hourOfDay = 0; } if (xm.equalsIgnoreCase("PM") && hourOfDay <= 11) { hourOfDay += 12; } break; default: return null; } Calendar c = Calendar.getInstance(); c.set(Calendar.YEAR, year); c.set(Calendar.MONTH, monthOfYear - 1); c.set(Calendar.DAY_OF_MONTH, dayOfMonth); c.set(Calendar.HOUR_OF_DAY, hourOfDay); c.set(Calendar.MINUTE, minuteOfHour); c.set(Calendar.SECOND, secondOfMinute); c.set(Calendar.MILLISECOND, 0); return new Date(c.getTimeInMillis()); }
From source file:es.tekniker.framework.ktek.util.Utils.java
private static long getTimeinMillis4TimeUTC(int hours, int minutes, int seconds) { Calendar c = Calendar.getInstance(); System.out.println("current: " + c.getTime()); TimeZone z = c.getTimeZone(); int offset = z.getRawOffset(); if (z.inDaylightTime(new Date())) { offset = offset + z.getDSTSavings(); }/*from w w w. ja v a 2 s.c o m*/ int offsetHrs = offset / 1000 / 60 / 60; int offsetMins = offset / 1000 / 60 % 60; System.out.println("offsetHrs: " + offsetHrs); System.out.println("offsetMins: " + offsetMins); c.set(Calendar.HOUR_OF_DAY, (hours - offsetHrs)); c.set(Calendar.MINUTE, (minutes - offsetMins)); c.set(Calendar.SECOND, seconds); System.out.println("GMT Time: " + c.getTime()); long timeinmillis = c.getTimeInMillis(); System.out.println(" system time in millis " + timeinmillis); return timeinmillis; }
From source file:com.jabyftw.easiercommands.Util.java
/** * Source: Essentials (found through Ban-Management) * <b>Letters used:</b> y mo w d h m s * * @param time string with the time, eg: "3w4h" - three weeks and four hours * @return the time in milliseconds//from w w w . jav a 2 s . com * @see <a href=https://github.com/BanManagement/BanManager/blob/master/src/main/java/me/confuser/banmanager/util/DateUtils.java>Credits to Essentials</a> */ public static long parseTimeDifference(@NotNull String time) { Pattern timePattern = Pattern.compile("(?:([0-9]+)\\s*y[a-z]*[,\\s]*)?" + "(?:([0-9]+)\\s*mo[a-z]*[,\\s]*)?" + "(?:([0-9]+)\\s*w[a-z]*[,\\s]*)?" + "(?:([0-9]+)\\s*d[a-z]*[,\\s]*)?" + "(?:([0-9]+)\\s*h[a-z]*[,\\s]*)?" + "(?:([0-9]+)\\s*m[a-z]*[,\\s]*)?" + "(?:([0-9]+)\\s*(?:s[a-z]*)?)?", Pattern.CASE_INSENSITIVE); Matcher matcher = timePattern.matcher(time); int years = 0, months = 0, weeks = 0, days = 0, hours = 0, minutes = 0, seconds = 0; boolean found = false; while (matcher.find()) { if (matcher.group() == null || matcher.group().isEmpty()) { continue; } for (int i = 0; i < matcher.groupCount(); i++) { if (matcher.group(i) != null && !matcher.group(i).isEmpty()) { found = true; break; } } if (found) { if (matcher.group(1) != null && !matcher.group(1).isEmpty()) years = Integer.parseInt(matcher.group(1)); if (matcher.group(2) != null && !matcher.group(2).isEmpty()) months = Integer.parseInt(matcher.group(2)); if (matcher.group(3) != null && !matcher.group(3).isEmpty()) weeks = Integer.parseInt(matcher.group(3)); if (matcher.group(4) != null && !matcher.group(4).isEmpty()) days = Integer.parseInt(matcher.group(4)); if (matcher.group(5) != null && !matcher.group(5).isEmpty()) hours = Integer.parseInt(matcher.group(5)); if (matcher.group(6) != null && !matcher.group(6).isEmpty()) minutes = Integer.parseInt(matcher.group(6)); if (matcher.group(7) != null && !matcher.group(7).isEmpty()) seconds = Integer.parseInt(matcher.group(7)); break; } } if (!found) throw new IllegalArgumentException("Date can't be parsed"); if (years > 20) throw new IllegalArgumentException("Date is too big"); Calendar calendar = new GregorianCalendar(); if (years > 0) calendar.add(Calendar.YEAR, years); if (months > 0) calendar.add(Calendar.MONTH, months); if (weeks > 0) calendar.add(Calendar.WEEK_OF_YEAR, weeks); if (days > 0) calendar.add(Calendar.DAY_OF_MONTH, days); if (hours > 0) calendar.add(Calendar.HOUR_OF_DAY, hours); if (minutes > 0) calendar.add(Calendar.MINUTE, minutes); if (seconds > 0) calendar.add(Calendar.SECOND, seconds); return calendar.getTimeInMillis() - System.currentTimeMillis(); }
From source file:adalid.commons.util.TimeUtils.java
public static synchronized Time getTime(java.util.Date date) { if (date == null) { return currentTime(); }//ww w .j a va 2 s. co m Calendar c = Calendar.getInstance(); c.setTimeInMillis(date.getTime()); c.set(Calendar.YEAR, 1970); c.set(Calendar.MONTH, Calendar.JANUARY); c.set(Calendar.DAY_OF_MONTH, 1); return new Time(c.getTimeInMillis()); }
From source file:com.espertech.esper.schedule.ScheduleComputeHelper.java
private static long getTime(ScheduleCalendar result, int year, String optionalTimeZone) { Calendar calendar; if (optionalTimeZone != null) { calendar = Calendar.getInstance(TimeZone.getTimeZone(optionalTimeZone)); } else {//from w ww . j a v a 2 s . c om calendar = Calendar.getInstance(); } calendar.set(year, result.getMonth() - 1, result.getDayOfMonth(), result.getHour(), result.getMinute(), result.getSecond()); calendar.set(Calendar.MILLISECOND, result.getMilliseconds()); return calendar.getTimeInMillis(); }
From source file:adalid.commons.util.TimeUtils.java
public static synchronized Date getDate(java.util.Date date) { if (date == null) { return currentDate(); }//from www . j a v a2 s . c o m Calendar c = Calendar.getInstance(); c.setTimeInMillis(date.getTime()); c.set(Calendar.HOUR_OF_DAY, 0); c.set(Calendar.MINUTE, 0); c.set(Calendar.SECOND, 0); c.set(Calendar.MILLISECOND, 0); return new Date(c.getTimeInMillis()); }
From source file:jp.iftc.androidasset.db.AssetInfo.java
private static long toDiffDate(long time) { //??//from www . ja va2s. co m Calendar nowcal = Calendar.getInstance(); int factor = 1; // // Calendar dateCal = Calendar.getInstance(); // dateCal.setTime(date); //long? long diffTime = nowcal.getTimeInMillis() - time; if (diffTime < 0) { factor = -1; diffTime = diffTime * factor; } // long second = diffTime / 1000; if (second < 60) { return 0; } // long minute = second / 60; if (minute < 60) { return 0; } // long hour = minute / 60; if (hour < 24) { return 0; } // long day = hour / 24; return day * factor; // //30?? // //1 // dateCal.add(Calendar.MONDAY, 1); // if (dateCal.after(nowcal)) { // return day + ""; // // } // // dateCal.setTime(date); //? // dateCal.add(Calendar.MONDAY, 12); //12 // if (dateCal.after(nowcal)) {//12 // for (int i=11; i>=1; i--) { // dateCal.setTime(date); //? // dateCal.add(Calendar.MONDAY, i); // if (dateCal.before(nowcal)) { // return i + ""; //i? // } // } // } // // return "1"; //1? }
From source file:fr.paris.lutece.plugins.mylutece.util.SecurityUtils.java
/** * Compute the maximum valid date of an account with the current time and * the parameters in the database.//from w w w . java 2 s . c o m * @param parameterService Parameter service to use * @param plugin The plugin * @return The maximum valid date of an account */ public static Timestamp getAccountMaxValidDate(IUserParameterService parameterService, Plugin plugin) { int nbDaysPasswordValid = getIntegerSecurityParameter(parameterService, plugin, MARK_ACCOUNT_LIFE_TIME); if (nbDaysPasswordValid <= 0) { return null; } Calendar calendare = new GregorianCalendar(Locale.getDefault()); calendare.add(Calendar.DAY_OF_MONTH, nbDaysPasswordValid); return new Timestamp(calendare.getTimeInMillis()); }
From source file:ru.org.linux.topic.TopicListController.java
/** * @param response/*www.j ava2 s . c o m*/ * @param topicListForm */ private static void setExpireHeaders(HttpServletResponse response, TopicListRequest topicListForm) { if (topicListForm.getMonth() == null) { response.setDateHeader("Expires", System.currentTimeMillis() + 60 * 1000); response.setDateHeader("Last-Modified", System.currentTimeMillis()); } else { long expires = System.currentTimeMillis() + 30 * 24 * 60 * 60 * 1000L; Calendar calendar = Calendar.getInstance(); calendar.set(topicListForm.getYear(), topicListForm.getMonth() - 1, 1); calendar.add(Calendar.MONTH, 1); long lastmod = calendar.getTimeInMillis(); if (lastmod < System.currentTimeMillis()) { response.setDateHeader("Expires", expires); response.setDateHeader("Last-Modified", lastmod); } else { response.setDateHeader("Expires", System.currentTimeMillis() + 60 * 1000); response.setDateHeader("Last-Modified", System.currentTimeMillis()); } } }