Example usage for java.util Calendar getTimeInMillis

List of usage examples for java.util Calendar getTimeInMillis

Introduction

In this page you can find the example usage for java.util Calendar getTimeInMillis.

Prototype

public long getTimeInMillis() 

Source Link

Document

Returns this Calendar's time value in milliseconds.

Usage

From source file:com.esri.cordova.geolocation.utils.JSONHelper.java

/**
 * Originates from a change in signal strength
 * @param signalStrength SignalStrength//ww  w .  j av a 2 s  . c  om
 * @return JSON
 */
public static String signalStrengthJSON(SignalStrength signalStrength) {
    final Calendar calendar = Calendar.getInstance();
    final JSONObject json = new JSONObject();

    try {
        json.put("provider", SIGNAL_STRENGTH); // Yep provider and type are same values
        json.put("type", SIGNAL_STRENGTH);
        json.put("timestamp", calendar.getTimeInMillis());
        json.put("cdmaDbm", signalStrength.getCdmaDbm());
        json.put("cdmaEcio", signalStrength.getCdmaEcio());
        json.put("evdoDbm", signalStrength.getEvdoDbm());
        json.put("evdoEcio", signalStrength.getEvdoEcio());
        json.put("evdoSnr", signalStrength.getEvdoSnr());
        json.put("gsmBitErrorRate", signalStrength.getGsmBitErrorRate());
        json.put("gsmSignalStrength", signalStrength.getGsmSignalStrength());

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            json.put("level", signalStrength.getLevel());
        }

        json.put("isGSM", signalStrength.isGsm());
    } catch (JSONException exc) {
        logJSONException(exc);
    }

    return json.toString();
}

From source file:osh.busdriver.MieleGatewayBusDriver.java

static private StartTimeDetails createStartTimeDetails(final UUID devUUID, long timestamp,
        MieleDeviceHomeBusData dev) {// www  .  j a v a2s.com

    StartTimeDetails startDetails = new StartTimeDetails(devUUID, timestamp);
    startDetails.setStartTime(-1);

    if (dev.getDeviceDetails() != null) {
        MieleDuration mieleStartTime = dev.getDeviceDetails().getStartTime();

        if (mieleStartTime != null) {
            int starttime = mieleStartTime.duration();

            if (starttime >= 0) {
                Calendar calNow = Calendar.getInstance();
                Calendar calStartTime = (Calendar) calNow.clone();

                calStartTime.set(Calendar.MINUTE, starttime % 60);
                calStartTime.set(Calendar.HOUR_OF_DAY, starttime / 60);

                if (calStartTime.before(calNow)) {
                    calStartTime.add(Calendar.DAY_OF_YEAR, 1);
                }

                startDetails.setStartTime(calStartTime.getTimeInMillis() / 1000L);
            }
        }
    }

    return startDetails;
}

From source file:Main.java

public static long ArrivalMilliseconds(String arrivalTime) {

    Calendar calendarToday = Calendar.getInstance();
    Calendar calendarTrainArrival = Calendar.getInstance();

    long millisecondsTrainArrival;

    int nowYear = calendarToday.get(Calendar.YEAR);
    int nowMonth = calendarToday.get(Calendar.MONTH);
    int nowDay = calendarToday.get(Calendar.DATE);

    int evalhr = 0;
    int evalmin = 0;
    int evalsec = 0;

    String delims = "[:]";
    String[] timesplit = arrivalTime.split(delims);

    evalhr = Integer.parseInt(timesplit[0]); //HR
    evalmin = Integer.parseInt(timesplit[1]); //MIN
    evalsec = Integer.parseInt(timesplit[2]); //SEC - VRE does not provide a schedule down to seconds, so ignore.

    calendarTrainArrival.set(nowYear, nowMonth, nowDay, evalhr, evalmin);
    millisecondsTrainArrival = calendarTrainArrival.getTimeInMillis();

    return millisecondsTrainArrival;
}

From source file:br.msf.commons.util.AbstractDateUtils.java

public static BigDecimal getDifferenceInDays(final Object date1, final Object date2,
        final boolean ignoreTimeInfo) {
    ArgumentUtils.rejectIfAnyNull(date1, date2);

    Calendar c1 = toUtcCalendar(date1);
    Calendar c2 = toUtcCalendar(date2);
    if (ignoreTimeInfo) {
        c1 = getTimeTruncatedInternal(c1);
        c2 = getTimeTruncatedInternal(c2);
    }/*w  ww  .j  a  v a2  s .  com*/
    final long l1 = c1.getTimeInMillis();
    final long l2 = c2.getTimeInMillis();
    BigDecimal res;
    if (l1 > l2) {
        res = new BigDecimal(l1 - l2);
    } else {
        res = new BigDecimal(l2 - l1);
    }
    return NumberUtils.round(res.divide(MILLISECS_PER_DAY, MathContext.DECIMAL128), 2);
}

From source file:com.esri.cordova.geolocation.utils.JSONHelper.java

/**
 * Parses data from PhoneStateListener.LISTEN_CELL_LOCATION.onCellLocationChanged
 * http://developer.android.com/reference/android/telephony/cdma/CdmaCellLocation.html
 * @param location CdmaCellLocation// w  w  w  . j  av  a  2s. co m
 * @return JSON
 */
public static String cdmaCellLocationJSON(CdmaCellLocation location) {

    final Calendar calendar = Calendar.getInstance();
    final JSONObject json = new JSONObject();

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2 && location != null) {
        try {
            json.put("provider", CELLLOCATION_PROVIDER);
            json.put("type", CDMA);
            json.put("timestamp", calendar.getTimeInMillis());
            json.put("baseStationId", location.getBaseStationId()); // -1 if unknown
            json.put("networkId", location.getNetworkId()); // -1 if unknown
            json.put("systemId", location.getSystemId()); // -1 if unknown
            json.put("baseStationLatitude",
                    CdmaCellLocation.convertQuartSecToDecDegrees(location.getBaseStationLatitude()));
            json.put("baseStationLongitude",
                    CdmaCellLocation.convertQuartSecToDecDegrees(location.getBaseStationLongitude()));
        } catch (JSONException exc) {
            logJSONException(exc);
        }
    }

    return json.toString();
}

From source file:com.esri.cordova.geolocation.utils.JSONHelper.java

/**
 * Converts CellInfoGsm into JSON//from   w  ww .  j  a  v a2s .  c  om
 * @param cellInfo CellInfoGsm
 * @return JSON
 */
public static String cellInfoGSMJSON(CellInfoGsm 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", GSM);
            json.put("timestamp", calendar.getTimeInMillis());

            final CellIdentityGsm identityGsm = cellInfo.getCellIdentity();

            json.put("cid", identityGsm.getCid());
            json.put("lac", identityGsm.getLac());
            json.put("mcc", identityGsm.getMcc());
            json.put("mnc", identityGsm.getMnc());

            if (returnSignalStrength) {
                final JSONObject jsonSignalStrength = new JSONObject();
                final CellSignalStrengthGsm cellSignalStrengthGsm = cellInfo.getCellSignalStrength();
                jsonSignalStrength.put("asuLevel", cellSignalStrengthGsm.getAsuLevel());
                jsonSignalStrength.put("dbm", cellSignalStrengthGsm.getDbm());
                jsonSignalStrength.put("level", cellSignalStrengthGsm.getLevel());

                json.put("cellSignalStrengthGsm", jsonSignalStrength);
            }
        } catch (JSONException exc) {
            logJSONException(exc);
        }
    }
    return json.toString();
}

From source file:com.esri.cordova.geolocation.utils.JSONHelper.java

/**
 * Converts CellInfoLte into JSON/*from  w w w .ja v a 2s.c o m*/
 * @param cellInfo CellInfoLte
 * @return JSON
 */
public static String cellInfoLTEJSON(CellInfoLte 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", LTE);
            json.put("timestamp", calendar.getTimeInMillis());

            final CellIdentityLte identityLte = cellInfo.getCellIdentity();

            json.put("ci", identityLte.getCi());
            json.put("mcc", identityLte.getMcc());
            json.put("mnc", identityLte.getMnc());
            json.put("pci", identityLte.getPci());
            json.put("tac", identityLte.getTac());

            if (returnSignalStrength) {
                final JSONObject jsonSignalStrength = new JSONObject();
                final CellSignalStrengthLte cellSignalStrengthLte = cellInfo.getCellSignalStrength();
                jsonSignalStrength.put("asuLevel", cellSignalStrengthLte.getAsuLevel());
                jsonSignalStrength.put("dbm", cellSignalStrengthLte.getDbm());
                jsonSignalStrength.put("level", cellSignalStrengthLte.getLevel());
                jsonSignalStrength.put("timingAdvance", cellSignalStrengthLte.getTimingAdvance());

                json.put("cellSignalStrengthLte", jsonSignalStrength);
            }
        } catch (JSONException exc) {
            logJSONException(exc);
        }
    }
    return json.toString();
}

From source file:com.esri.cordova.geolocation.utils.JSONHelper.java

/**
 * Converts CellInfoWcdma into JSON//w  ww . j a  v  a  2s  .  co m
 * Some devices may not work correctly:
 * - Reference 1: https://code.google.com/p/android/issues/detail?id=191492
 * - Reference 2: http://stackoverflow.com/questions/17815062/cellidentitygsm-on-android
 * @param cellInfo CellInfoWcdma
 * @return JSON
 */
public static String cellInfoWCDMAJSON(CellInfoWcdma 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", WCDMA);
            json.put("timestamp", calendar.getTimeInMillis());

            final CellIdentityWcdma identityWcdma = cellInfo.getCellIdentity();

            json.put("cid", identityWcdma.getCid());
            json.put("lac", identityWcdma.getLac());
            json.put("mcc", identityWcdma.getMcc());
            json.put("mnc", identityWcdma.getMnc());
            json.put("psc", identityWcdma.getPsc());

            if (returnSignalStrength) {
                final JSONObject jsonSignalStrength = new JSONObject();
                final CellSignalStrengthWcdma cellSignalStrengthWcdma = cellInfo.getCellSignalStrength();
                jsonSignalStrength.put("asuLevel", cellSignalStrengthWcdma.getAsuLevel());
                jsonSignalStrength.put("dbm", cellSignalStrengthWcdma.getDbm());
                jsonSignalStrength.put("level", cellSignalStrengthWcdma.getLevel());

                json.put("cellSignalStrengthWcdma", jsonSignalStrength);
            }
        } catch (JSONException exc) {
            logJSONException(exc);
        }
    }
    return json.toString();
}

From source file:com.concursive.connect.web.modules.profile.utils.ProjectUtils.java

public static int queryWhatsNewCount(Connection db, int userId) throws SQLException {
    int count = 0;
    Calendar cal = Calendar.getInstance();
    cal.add(Calendar.DAY_OF_MONTH, -2);
    Timestamp alertRangeStart = new Timestamp(cal.getTimeInMillis());
    // Latest News
    BlogPostList newsList = new BlogPostList();
    newsList.setForUser(userId);//from  w w  w.  j av  a 2s .co  m
    newsList.setAlertRangeStart(alertRangeStart);
    newsList.setCurrentNews(Constants.TRUE);
    count += newsList.queryCount(db);
    // Latest Issues
    TopicList topicList = new TopicList();
    topicList.setForUser(userId);
    topicList.setAlertRangeStart(alertRangeStart);
    count += topicList.queryCount(db);
    // Latest Files
    FileItemList fileItemList = new FileItemList();
    fileItemList.setLinkModuleId(Constants.PROJECTS_FILES);
    fileItemList.setForProjectUser(userId);
    fileItemList.setAlertRangeStart(alertRangeStart);
    count += fileItemList.queryCount(db);
    // Latest Wikis
    WikiList wikiList = new WikiList();
    wikiList.setForUser(userId);
    wikiList.setAlertRangeStart(alertRangeStart);
    count += wikiList.queryCount(db);
    return count;
}

From source file:Main.java

/**
 * Parses an xs:dateTime attribute value, returning the parsed timestamp in milliseconds since
 * the epoch.//from  ww w .  jav  a2  s  .c o  m
 *
 * @param value The attribute value to parse.
 * @return The parsed timestamp in milliseconds since the epoch.
 */
public static long parseXsDateTime(String value) throws ParseException {
    Matcher matcher = XS_DATE_TIME_PATTERN.matcher(value);
    if (!matcher.matches()) {
        throw new ParseException("Invalid date/time format: " + value, 0);
    }

    int timezoneShift;
    if (matcher.group(9) == null) {
        // No time zone specified.
        timezoneShift = 0;
    } else if (matcher.group(9).equalsIgnoreCase("Z")) {
        timezoneShift = 0;
    } else {
        timezoneShift = ((Integer.parseInt(matcher.group(12)) * 60 + Integer.parseInt(matcher.group(13))));
        if (matcher.group(11).equals("-")) {
            timezoneShift *= -1;
        }
    }

    Calendar dateTime = new GregorianCalendar(TimeZone.getTimeZone("GMT"));

    dateTime.clear();
    // Note: The month value is 0-based, hence the -1 on group(2)
    dateTime.set(Integer.parseInt(matcher.group(1)), Integer.parseInt(matcher.group(2)) - 1,
            Integer.parseInt(matcher.group(3)), Integer.parseInt(matcher.group(4)),
            Integer.parseInt(matcher.group(5)), Integer.parseInt(matcher.group(6)));
    if (!TextUtils.isEmpty(matcher.group(8))) {
        final BigDecimal bd = new BigDecimal("0." + matcher.group(8));
        // we care only for milliseconds, so movePointRight(3)
        dateTime.set(Calendar.MILLISECOND, bd.movePointRight(3).intValue());
    }

    long time = dateTime.getTimeInMillis();
    if (timezoneShift != 0) {
        time -= timezoneShift * 60000;
    }

    return time;
}