Example usage for java.util Calendar setTimeInMillis

List of usage examples for java.util Calendar setTimeInMillis

Introduction

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

Prototype

public void setTimeInMillis(long millis) 

Source Link

Document

Sets this Calendar's current time from the given long value.

Usage

From source file:at.pagu.soldockr.core.query.CriteriaTest.java

@Test
public void testIsWithJavaDateValue() {
    DateTime dateTime = new DateTime(2012, 8, 21, 6, 35, 0, DateTimeZone.UTC);
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeZone(TimeZone.getTimeZone("UTC"));
    calendar.setTimeInMillis(dateTime.getMillis());

    Criteria criteria = new Criteria("dateField").is(calendar.getTime());
    Assert.assertEquals("dateField:2012\\-08\\-21T06\\:35\\:00.000Z", criteria.createQueryString());
}

From source file:desktopsearch.ExploreFiles.java

private void RecursivelyExplore(File Directory) {

    String[] List = Directory.list();
    String AbsPath = Directory.getAbsolutePath() + "/";
    String SQLQuery = null;/* ww w.  j a v a 2 s  .  c om*/
    ArrayList<String> DirList = new ArrayList();

    String FormattedPath = Directory.getPath();
    if (FormattedPath.contains("'")) {
        FormattedPath = FormattedPath.replace("'", "''");
    }

    try {
        for (int i = 0; i < List.length; i++) {
            File path = new File(AbsPath + List[i]);
            Path Location = Paths.get(path.getAbsolutePath());

            FileTime LastModifiedTime = Files.getLastModifiedTime(Location);
            Calendar calendar = Calendar.getInstance();
            calendar.setTimeInMillis(LastModifiedTime.toMillis());

            try {

                if (path.isFile()) {

                    String Type = FilenameUtils.getExtension(Directory.getPath() + "/" + List[i]);

                    if (Type.endsWith("~") || Type.equals("")) {
                        Type = "Text";
                    }

                    if (List[i].contains("'")) {
                        List[i] = List[i].replace("'", "''");
                        System.out.println(List[i]);
                    }

                    SQLQuery = "INSERT INTO FileInfo VALUES('" + Directory.getPath() + "','" + List[i] + "','"
                            + Type + "','" + calendar.getTime() + "'," + (path.length() / 1024) + ");";

                } else {

                    if (List[i].contains("'")) {
                        List[i] = List[i].replace("'", "''");
                        System.out.println(List[i]);
                    }

                    if (!Files.isSymbolicLink(Location)) {
                        long size = FileUtils.sizeOfDirectory(path);
                        SQLQuery = "INSERT INTO FileInfo VALUES('" + Directory.getPath() + "','" + List[i]
                                + "','FOLDER','" + calendar.getTime() + "'," + size + ");";
                    } else {

                        SQLQuery = "INSERT INTO FileInfo VALUES('" + Directory.getPath() + "','" + List[i]
                                + "','LINK','" + calendar.getTime() + "',0);";
                    }

                    DirList.add(List[i]);
                }

                output.println(SQLQuery);
            } catch (Exception exp) {
                exp.printStackTrace();
            }
            ;

        }

        for (int i = 0; i < DirList.size(); i++) {
            File subDir = new File(AbsPath + DirList.get(i));
            Path path = Paths.get(AbsPath + DirList.get(i));
            if (subDir.canRead() && !Files.isSymbolicLink(path)) {
                RecursivelyExplore(subDir);
            }

        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:org.opennms.ng.services.polloutagesconfig.PollOutagesConfigManager.java

/**
 * {@inheritDoc}//ww w  .  j a v a2 s . co m
 * <p/>
 * Return if time is part of specified outage.
 */
@Override
public boolean isTimeInOutage(final long time, final String outName) {
    final Outage out = getOutage(outName);
    if (out == null) {
        return false;
    }

    final Calendar cal = Calendar.getInstance();
    cal.setTimeInMillis(time);
    return isTimeInOutage(cal, out);
}

From source file:com.github.amsacode.predict4java.PassPredictor.java

public Long getUplinkFreq(final Long freq, final Date date) throws SatNotFoundException {
    final Calendar cal = Calendar.getInstance(TZ);
    cal.clear();//from   w  ww.j a  v  a 2  s . c om
    cal.setTimeInMillis(date.getTime());
    final SatPos satPos = getSatPos(cal.getTime());
    final double rangeRate = satPos.getRangeRate();
    return (long) ((double) freq * (SPEED_OF_LIGHT + rangeRate * 1000.0) / SPEED_OF_LIGHT);
}

From source file:com.github.amsacode.predict4java.PassPredictor.java

/**
 * Gets the downlink frequency corrected for doppler.
 * /*from  w  w  w.j  ava2 s  . co m*/
 * @param freq
 *            the original frequency in Hz
 * @return the doppler corrected frequency in Hz
 * @throws InvalidTleException
 *             bad TLE passed in
 * @throws SatNotFoundException
 */
public Long getDownlinkFreq(final Long freq, final Date date) throws SatNotFoundException {
    // get the current position
    final Calendar cal = Calendar.getInstance(TZ);
    cal.clear();
    cal.setTimeInMillis(date.getTime());
    final SatPos satPos = getSatPos(cal.getTime());
    final double rangeRate = satPos.getRangeRate();
    return (long) ((double) freq * (SPEED_OF_LIGHT - rangeRate * 1000.0) / SPEED_OF_LIGHT);
}

From source file:jef.tools.DateUtils.java

/**
 * ??/??//from   w  ww  . j  a  v  a2s  . com
 * 
 * @param date
 *            
 * @param field
 *            ??field. Calendar?
 * @return ?
 */
public final static void truncate(Calendar date, int field) {
    date.setTimeInMillis(org.apache.commons.lang.time.DateUtils.truncate(date, field).getTimeInMillis());
}

From source file:ddf.catalog.cache.impl.ResourceCacheImplTest.java

private MetacardImpl generateMetacard() throws URISyntaxException {
    MetacardImpl metacard = new MetacardImpl();
    metacard.setAttribute(Metacard.CHECKSUM, "1");
    metacard.setSourceId("source1");
    metacard.setId("id123");
    metacard.setContentTypeName("content-type-name");
    metacard.setContentTypeVersion("content-type-version");
    Calendar c = Calendar.getInstance();
    c.setTimeInMillis(1400673600); // hardcode date to ensure it is the same time.
    metacard.setCreatedDate(c.getTime());
    metacard.setEffectiveDate(c.getTime());
    metacard.setExpirationDate(c.getTime());
    metacard.setModifiedDate(c.getTime());
    metacard.setLocation("POINT(0 10)");
    metacard.setMetadata("<metadata>abc</metadata>");
    metacard.setResourceSize("100");
    metacard.setResourceURI(new URI("https://github.com/codice"));
    metacard.setTitle("title");
    return metacard;
}

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/*from  ww w.  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);
    }
}

From source file:de.xwic.appkit.webbase.trace.ui.TraceStatModel.java

/**
 * Load the data./*from  w w w .  j  a va  2s .c o m*/
 */
public void refresh() {

    ITraceDataManager dataManager = Trace.getDataManager();
    if (dataManager != null) {

        List<ITraceContext> history = dataManager.getTraceHistory();

        if (history.size() != 0) {
            // figure out span
            long oldest = history.get(0).getStartTime();
            long newest = history.get(history.size() - 1).getStartTime();
            long maxAge = newest - maxSpan; // max five days.

            long startTime = oldest < maxAge ? maxAge : oldest;
            long span = newest - startTime;

            boolean useMinutes = span < HOUR * 2; // use minutes scale if span is < 2 hours 

            // create a "cube"
            // create a new temporary DataPoolManager.
            IDataPool dpTemp = dataPoolManager.createDataPool("temp-" + System.currentTimeMillis());
            IMeasure meDuration = dpTemp.createMeasure(MEASURE_DURATION);
            IMeasure meCount = dpTemp.createMeasure(MEASURE_COUNT);
            IMeasure mePeak = dpTemp.createMeasure(MEASURE_PEAK);

            // create time scale
            DateFormat df;
            if (useMinutes) {
                df = new SimpleDateFormat("HH:mm");
            } else {
                df = new SimpleDateFormat("dd-MMM HH");
            }

            IDimension dimTime = dpTemp.createDimension(DIM_TIME);
            Calendar cal = Calendar.getInstance();
            cal.setTimeInMillis(startTime);
            int field;
            if (useMinutes) {
                field = Calendar.MINUTE;
            } else {
                field = Calendar.HOUR_OF_DAY;
            }
            do {
                String timeKey = df.format(cal.getTime());
                if (!useMinutes) {
                    timeKey = timeKey + ":00";
                }
                dimTime.createDimensionElement(timeKey);

                cal.add(field, 1);

            } while (cal.getTimeInMillis() <= newest);
            // add one more
            String timeKey = df.format(cal.getTime());
            if (!useMinutes) {
                timeKey = timeKey + ":00";
            }
            dimTime.createDimensionElement(timeKey);

            // create cube
            ICube cube = dpTemp.createCube(CUBE_STATS, new IDimension[] { dimTime },
                    new IMeasure[] { meDuration, meCount, mePeak });

            // load the data
            for (ITraceContext tcx : history) {
                if (tcx.getStartTime() >= startTime) {
                    String key = df.format(new Date(tcx.getStartTime()));
                    if (!useMinutes) {
                        key = key + ":00";
                    }
                    if (dimTime.containsDimensionElement(key)) {
                        IDimensionElement elm = dimTime.getDimensionElement(key);
                        Key cKey = cube.createKey(elm);
                        double value = tcx.getDuration();
                        cube.addCellValue(cKey, meDuration, value);
                        cube.addCellValue(cKey, meCount, 1);

                        Double val = cube.getCellValue(cKey, mePeak);
                        if (val == null || val < value) {
                            cube.setCellValue(cKey, mePeak, value);
                        }
                    } else {
                        log.warn("Can not find element with key " + key + " in time dimension??");
                    }
                }
            }

            // scan for scale
            double h = 0;
            double hPeak = 0;
            double hCnt = 0;
            double hDuration = 0;
            for (IDimensionElement de : dimTime.getDimensionElements()) {
                Key cKey = cube.createKey(de);
                Double valDur = cube.getCellValue(cKey, meDuration);
                Double valPeak = cube.getCellValue(cKey, mePeak);
                Double valCnt = cube.getCellValue(cKey, meCount);
                if (valDur != null && valCnt != null) {
                    double avr = valDur / valCnt;
                    if (avr > h) {
                        h = avr;
                    }
                }
                if (valPeak != null && valPeak > hPeak) {
                    hPeak = valPeak;
                }
                if (valCnt != null && valCnt > hCnt) {
                    hCnt = valCnt;
                }
                if (valDur != null && valDur > hDuration) {
                    hDuration = valDur;
                }
            }
            highestValue = h;
            highestPeak = hPeak;
            highestCount = hCnt;
            highestDuration = hDuration;

            // switch pools

            if (dataPool != null) {
                dataPoolManager.releaseDataPool(dataPool);
            }
            dataPool = dpTemp;

        }

    }

    setChanged();
    notifyObservers();

}

From source file:com.yattatech.dbtc.facade.SystemFacade.java

/**
 * Actually that only checks if current year is less than
 * Minimum one supported by application. That values is 
 * the 2nd position in {@link Constants#MIN_CALENDAR_DATE}
 * //from  w  w w .j  a  v a2s.  co m
 * @return boolean 
 */
public boolean isDeviceClockOutOfSync() {
    final Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(System.currentTimeMillis());
    final int year = calendar.get(Calendar.YEAR);
    final int minYear = Constants.MIN_CALENDAR_DATE[1];
    if (Debug.isDebugable()) {
        Debug.d(TAG, "isDeviceClockOutOfSync currentYear=" + year + "minimulSupportedYear=" + minYear);
    }
    return year < minYear;
}