Example usage for java.util Date setTime

List of usage examples for java.util Date setTime

Introduction

In this page you can find the example usage for java.util Date setTime.

Prototype

public void setTime(long time) 

Source Link

Document

Sets this Date object to represent a point in time that is time milliseconds after January 1, 1970 00:00:00 GMT.

Usage

From source file:org.silverpeas.components.resourcesmanager.model.Category.java

public Date getCreationDate() {
    if (StringUtil.isLong(creationDate)) {
        Date create = new Date();
        create.setTime(Long.parseLong(creationDate));
        return create;
    }/*from   w  w w. jav a  2 s  . c om*/
    return null;
}

From source file:org.silverpeas.components.resourcesmanager.model.Category.java

public Date getUpdateDate() {
    if (StringUtil.isLong(updateDate)) {
        Date update = new Date();
        update.setTime(Long.parseLong(updateDate));
        return update;
    }//from w ww.  j  a  va  2s  .  co m
    return null;
}

From source file:com.siblinks.ws.service.impl.FavouriteVideoServiceImpl.java

/**
 * {@inheritDoc}//from  w w  w  .j  a  v  a 2s. c  o  m
 */
@Override
@RequestMapping(value = "/favouriteLimit", method = RequestMethod.GET)
public ResponseEntity<Response> getFavouriteByUid(@RequestParam(value = "uid") final int uid,
        @RequestParam(value = "limit") final int limit,
        @RequestParam(value = "favouritetime") final long favouritetime) throws Exception {
    // Cast to Date
    Date dateFavourite = new Date();
    dateFavourite.setTime(favouritetime);

    // Get all favourite by user id
    List<Object> readObjects = dao.readObjects(SibConstants.SqlMapper.SQL_VIDEO_FAVOURITE_READ_LIMIT,
            new Object[] { uid, dateFavourite, limit });

    logger.info("getAllFavouriteByUid success " + new Date());

    SimpleResponse reponse = new SimpleResponse("" + Boolean.TRUE, "favouriteService", "getAllFavouriteByUid",
            readObjects);
    ResponseEntity<Response> entity = new ResponseEntity<Response>(reponse, HttpStatus.OK);
    return entity;
}

From source file:io.github.runassudo.ptoffline.activities.TripDetailActivity.java

private void reload() {
    if (mMenu != null) {
        mMenu.findItem(R.id.action_reload).setActionView(R.layout.actionbar_progress_actionview);
    }//  ww w  . j  a v  a2 s. c om
    AsyncQueryTripsTask task = new AsyncQueryTripsTask(this, this);

    // use a new date slightly earlier to avoid missing the right trip
    Date new_date = new Date();
    new_date.setTime(trip.getFirstDepartureTime().getTime() - 5000);

    task.setFrom(from);
    task.setTo(to);
    task.setDate(new_date);
    task.setDeparture(true);
    task.setProducts(new HashSet<>(products));

    task.execute();
}

From source file:org.ambraproject.action.HomepageActionTest.java

@DataProvider(name = "expectedInfo")
public Object[][] getExpectedInfo() throws Exception {

    //make sure to use a journal for this test, so we don't get 'recent' articles that were added by other unit tests
    Journal journal = new Journal();
    journal.seteIssn("8675-309");
    journal.setJournalKey("HomePageActionTestJournal");
    dummyDataStore.store(journal);/*  w ww.  ja  v  a  2s  . c om*/

    //create some recent articles and not recent articles w/ dates
    //creating 4 so that the algorithm has to look farther back in time to get them all

    List<Pair<String, String>> recentArticles = new ArrayList<Pair<String, String>>(5);

    Random r = new Random();
    for (int x = 1; x < 5; x++) {
        String doi = new StringBuilder("recent-article-doi-THAT-SHOULD-SHOW-doi").append(x).toString();
        String title = new StringBuilder("recent-article-doi-THAT-SHOULD-SHOW-title").append(x).toString();
        Article a = new Article(doi);
        a.setTitle(title);
        a.setTypes(new HashSet<String>(Arrays.asList("http://rdf.plos.org/RDF/articleType/Research%20Article",
                "http://rdf.plos.org/RDF/articleType/research-article")));

        //randomize date - we know a priori recent articles should be within last 7 days; 86400000 milliseconds in a day
        Date d = new Date();
        d.setTime(d.getTime() - d.getTime() % 86400000L); /* set to midnight */
        d.setTime(d.getTime() - (long) r.nextInt(604800000)); /*some random time within the last 7 days*/
        a.setDate(d);
        a.seteIssn("8675-309");
        dummyDataStore.store(a);

        recentArticles.add(new Pair<String, String>(doi, title));

        //solr
        solr.addDocument(new String[][] { { "id", doi }, { "title_display", title },
                { "publication_date", dateFormatter.format(a.getDate()) }, { "article_type_facet", "article" },
                { "doc_type", "full" }, { "cross_published_journal_key", journal.getJournalKey() } });
    }

    //article within date w/ image-type doi that should be discarded on init - in HomePageAction.java:initRecentArticles()
    //"10.1371/image" is the string being searched on for discarding results
    String doi = new String("recent-article-that-SHOULD-NOT-SHOW-10.1371/image");
    String title = new String("recent-article-that-SHOULD-NOT-SHOW title");
    Article a = new Article(doi);
    a.setTitle(title);
    a.setTypes(new HashSet<String>(Arrays.asList("http://rdf.plos.org/RDF/articleType/Issue%20Image")));

    Date d = new Date();
    d.setTime(d.getTime() - (long) r.nextInt(604800000)); /*some random time within the last 7 days*/
    a.setDate(d);
    a.seteIssn("8675-309");
    dummyDataStore.store(a);

    solr.addDocument(new String[][] { { "id", doi }, { "title_display", title },
            { "publication_date", dateFormatter.format(a.getDate()) }, { "article_type_facet", "article" },
            { "doc_type", "full" }, { "cross_published_journal_key", journal.getJournalKey() } });

    //article beyond the date that should show up
    a = new Article("not-recent-article-doi-THAT-SHOULD-SHOW-doi");
    a.setTitle("not-recent-article-doi-THAT-SHOULD-SHOW-title");
    d = new Date();
    d.setTime(d.getTime() - 691200000L); /* set to time outside range */
    a.setDate(d);
    a.seteIssn("8675-309");
    a.setTypes(new HashSet<String>(Arrays.asList("http://rdf.plos.org/RDF/articleType/Research%20Article",
            "http://rdf.plos.org/RDF/articleType/research-article")));

    dummyDataStore.store(a);
    recentArticles.add(new Pair<String, String>(a.getDoi(), a.getTitle()));

    solr.addDocument(new String[][] { { "id", "not-recent-article-doi-THAT-SHOULD-SHOW-doi" },
            { "title_display", "not-recent-article-doi-THAT-SHOULD-SHOW-title" },
            { "publication_date", dateFormatter.format(a.getDate()) }, { "article_type_facet", "article" },
            { "doc_type", "full" }, { "cross_published_journal_key", journal.getJournalKey() } });

    //article beyond days to show that should NOT show up
    a = new Article("not-recent-article-doi-that-SHOULD-NOT-show-doi");
    a.setTitle("not-recent-article-doi-that-should-NOT-show-title");
    d = new Date();
    d.setTime(
            d.getTime() - 950400000L); /* set to time outside range + search interval used to go back in time*/
    a.setDate(d);
    a.seteIssn("8675-309");
    a.setTypes(new HashSet<String>(Arrays.asList("http://rdf.plos.org/RDF/articleType/Research%20Article",
            "http://rdf.plos.org/RDF/articleType/research-article")));

    dummyDataStore.store(a);

    return new Object[][] { { journal, recentArticles } };
}

From source file:de.xirp.chart.ChartManager.java

/**
 * This method creates a//w ww  . j  a va2 s. c o  m
 * {@link org.jfree.data.time.TimeSeriesCollection} from the given
 * {@link de.xirp.db.Record} and key array. The
 * record is evaluated from the given start to the given stop time
 * or is evaluated completely if the flag <code>origTime</code>
 * is set to <code>true</code>. <br>
 * <br>
 * The method also fills the given
 * <code>List&lt;Observed&gt;</code> with the found
 * {@link de.xirp.db.Observed} value objects. This
 * list is used by the
 * {@link de.xirp.chart.ChartManager#exportAutomatically(List, JFreeChart)}
 * method. <br>
 * <br>
 * This is done because the code base is the the. The
 * {@link de.xirp.db.Observed} objects are created
 * from a database query. To create a chart the date must be
 * contained in a {@link org.jfree.data.time.TimeSeriesCollection}.
 * The export methods in
 * {@link de.xirp.chart.ChartUtil} works with a
 * <code>List&lt;Observed&gt;</code>. The database query
 * delivers a <code>List&lt;Observed&gt;</code>, so the values
 * are converted to a
 * {@link org.jfree.data.time.TimeSeriesCollection} and then are
 * copied to the <code>all</code> list to be used laster on in
 * the
 * {@link de.xirp.chart.ChartManager#exportAutomatically(List, JFreeChart)}
 * method.
 * 
 * @param all
 *            <code>null</code> or empty List <b>not</b>
 *            permitted.<br>
 *            Must be a <code>new</code> List.
 * @param record
 *            The record containing the data.
 * @param keys
 *            The keys to use.
 * @param origTime
 *            A flag indicating if the original time should be
 *            used.
 * @param stop
 *            The start time.
 * @param start
 *            The stop time.
 * @return A <code>TimeSeriesCollection</code> with the values
 *         of the record for the time interval.
 * @see org.jfree.data.time.TimeSeriesCollection
 * @see de.xirp.db.Observed
 * @see de.xirp.db.Record
 * @see de.xirp.chart.ChartUtil
 * @see de.xirp.chart.ChartManager#exportAutomatically(java.util.List,
 *      org.jfree.chart.JFreeChart)
 * @see org.jfree.chart.JFreeChart
 */
private static TimeSeriesCollection createTimeSeriesAndFillAllObservedList(List<Observed> all, Record record,
        String[] keys, boolean origTime, long start, long stop) {

    TimeSeriesCollection dataset = new TimeSeriesCollection();
    Date date = new Date();
    List<Observed> obs;
    for (String keyname : keys) {
        TimeSeries ts = new TimeSeries(keyname, Millisecond.class);
        if (origTime) {
            obs = ChartDatabaseUtil.getObservedList(record, keyname);
        } else {
            obs = ChartDatabaseUtil.getObservedList(record, keyname, start, stop);
        }
        for (Observed o : obs) {
            date.setTime(o.getTimestamp());
            ts.addOrUpdate(new Millisecond(date), o.getValue());
        }
        all.addAll(obs);
        dataset.addSeries(ts);
    }
    return dataset;
}

From source file:de.janrenz.app.mediathek.RemoteImageCursorAdapter.java

@SuppressWarnings("deprecation")
@Override/*  w w  w  .j a  v a2s .  c om*/
public void bindView(View v, Context context, Cursor c) {

    String title = c.getString(c.getColumnIndexOrThrow("title"));
    String subtitle = c.getString(c.getColumnIndexOrThrow("subtitle"));
    String imagePath = c.getString(c.getColumnIndexOrThrow("image"));
    String startTime = c.getString(c.getColumnIndexOrThrow("startTime"));
    String startTimeAsTimestamp = c.getString(c.getColumnIndex("startTimeAsTimestamp"));
    String isLive = c.getString(c.getColumnIndex("isLive"));
    if (this.layout == R.layout.headline_item_grid) {
        final View vl = v;

        v.findViewById(R.id.thumbnail).getViewTreeObserver()
                .addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
                    @Override
                    public void onGlobalLayout() {

                        try {

                            View imgView = vl.findViewById(R.id.thumbnail);
                            imgView.getViewTreeObserver().removeGlobalOnLayoutListener(this);
                            ViewGroup.LayoutParams layout = imgView.getLayoutParams();
                            layout.height = imgView.getWidth() / 16 * 9;
                            imgView.setLayoutParams(layout);
                        } catch (Exception e) {
                        }
                    }
                });
    }

    /**
     * Next set the text of the entry.
     */
    if (isLive.equalsIgnoreCase("true")) {
        v.findViewById(R.id.live).setVisibility(View.VISIBLE);
        //v.setBackgroundColor(   context.getResources().getColor(R.color.highlight_live_list));
    } else {
        v.findViewById(R.id.live).setVisibility(View.GONE);
        //v.setBackgroundColor(   context.getResources().getColor(R.color.list_background));
    }

    TextView title_text = (TextView) v.findViewById(R.id.text_view);
    if (title_text != null) {
        title_text.setText(title);
    }

    TextView subtitle_text = (TextView) v.findViewById(R.id.text_view_sub);
    if (subtitle_text != null) {
        subtitle_text.setText(subtitle);
    }
    TextView subtitle2_text = (TextView) v.findViewById(R.id.text_view_sub2);
    if (subtitle2_text != null) {
        Date dt = new Date();
        // z.B. 'Fri Jan 26 19:03:56 GMT+01:00 2001'
        dt.setTime(Integer.parseInt(startTimeAsTimestamp) * 1000);
        dt.setHours(0);
        dt.setMinutes(0);
        dt.setSeconds(0);
        subtitle2_text.setText("ARD > " + startTime + " Uhr");
    }
    /**
     * Set the image
     */
    DisplayImageOptions loadingOptions = new DisplayImageOptions.Builder()
            ///.showStubImage(R.drawable.abs__item_background_holo_light)
            //.imageScaleType(ImageScaleType.EXACTLY)
            // .showImageForEmptyUri(R.drawable.ic_empty)
            //  .memoryCache(new WeakMemoryCache())
            .cacheInMemory()
            //.cacheOnDisc()
            .build();
    ImageView image_view = (ImageView) v.findViewById(R.id.thumbnail);

    if (image_view != null) {

        if (this.layout == R.layout.headline_item_grid) {
            imagePath = imagePath + "/" + 320;

        } else {

            imagePath = imagePath + "/" + 150;
        }
        ImageLoader.getInstance().displayImage(imagePath, image_view, loadingOptions);
    }
}

From source file:nl.sidn.dnslib.message.records.dnssec.RRSIGResourceRecord.java

@Override
public String toZone(int maxLength) {

    Date exp = new Date();
    exp.setTime((long) (signatureExpiration * 1000));

    Date incep = new Date();
    incep.setTime((long) (signatureInception * 1000));

    SimpleDateFormat fmt = new SimpleDateFormat("YYYYMMddHHmmss");
    fmt.setTimeZone(TimeZone.getTimeZone("UTC"));

    return super.toZone(maxLength) + "\t" + typeCovered.name() + " " + algorithm.getValue() + " " + labels + " "
            + originalTtl + " " + fmt.format(exp) + "(\n\t\t\t\t\t" + fmt.format(incep) + " " + (int) keytag
            + " " + signerName + "\n\t\t\t\t\t"
            + new Base64(36, "\n\t\t\t\t\t".getBytes()).encodeAsString(signature) + " )";
}

From source file:nl.sidn.dnslib.message.records.dnssec.RRSIGResourceRecord.java

@Override
public JsonObject toJSon() {
    Date exp = new Date();
    exp.setTime((long) (signatureExpiration * 1000));

    Date incep = new Date();
    incep.setTime((long) (signatureInception * 1000));

    JsonObjectBuilder builder = super.createJsonBuilder();
    return builder
            .add("rdata", Json.createObjectBuilder().add("type-covered", typeCovered.name())
                    .add("algorithm", algorithm.name()).add("labels", labels).add("original-ttl", originalTtl)
                    .add("sig-exp", DATE_FMT.format(exp)).add("sig-inc", DATE_FMT.format(incep))
                    .add("keytag", (int) keytag).add("signer-name", signerName)
                    .add("signature", new Base64(Integer.MAX_VALUE, "".getBytes()).encodeAsString(signature)))
            .build();/*from   w  w w  .  j a v a2  s  .co  m*/
}

From source file:gda.data.metadata.icat.XMLIcat.java

@Override
protected String getValue(String visitIDFilter, String userNameFilter, String accessName) throws Exception {

    String filepath = "file:" + LocalProperties.get(URL_PROP);
    Resource xmlfile = new FileSystemResourceLoader().getResource(filepath);
    XmlBeanFactory bf = new XmlBeanFactory(xmlfile);

    long tolerance = LocalProperties.getAsInt(SHIFT_TOL_PROP, 1440);

    // if not filtering on visit ID
    if (visitIDFilter == null || visitIDFilter.isEmpty()) {

        //loop over all the beans
        String values = "";
        Map<String, XMLIcatEntry> beans = bf.getBeansOfType(XMLIcatEntry.class);
        for (XMLIcatEntry bean : beans.values()) {
            // filter on username
            String names[] = bean.getUsernames().split(",");
            if (ArrayUtils.contains(names, userNameFilter)) {

                // filter on date
                Date now;//from   w w  w.  j  a v a 2 s. c om
                if (operatingDate != null) {
                    now = operatingDate;
                } else {
                    now = new Date();
                }

                Date start = formatter.parse(bean.getExperimentStart());
                Date end = formatter.parse(bean.getExperimentStart());
                start.setTime(start.getTime() - tolerance * 60000);// tolerance is in minutes but getTime returns in
                // ms
                end.setTime(end.getTime() + tolerance * 60000); // tolerance is in minutes but getTime returns in ms

                if (now.after(start) && now.before(end)) {

                    // add to return string
                    try {
                        if (values.isEmpty()) {
                            values = BeanUtils.getProperty(bean, accessName);
                        } else {
                            values += "," + BeanUtils.getProperty(bean, accessName);
                        }
                    } catch (Exception e) {
                        logger.warn("Exception trying to get property " + accessName + " from bean.", e);
                    }
                }
            }
        }

        // return the values string
        if (values.isEmpty()) {
            return null;
        }
        return values;
    }

    // else find the experiment for that visit and get its property
    XMLIcatEntry visit = bf.getBean(visitIDFilter, XMLIcatEntry.class);
    String names[] = visit.getUsernames().split(",");
    if (ArrayUtils.contains(names, userNameFilter)) {
        try {
            return BeanUtils.getProperty(visit, accessName);
        } catch (Exception e) {
            logger.warn("Exception trying to get property " + accessName + " from bean.", e);
        }
    }

    // else 
    return null;

}