Example usage for java.util Date toString

List of usage examples for java.util Date toString

Introduction

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

Prototype

public String toString() 

Source Link

Document

Converts this Date object to a String of the form:
 dow mon dd hh:mm:ss zzz yyyy
where:
  • dow is the day of the week ( Sun, Mon, Tue, Wed, Thu, Fri, Sat ).

    Usage

    From source file:com.redhat.victims.plugin.jenkins.VictimsPostBuildScanner.java

    /**
     * Updates the database according to the given configuration
     * /*from   www .ja v a 2 s .  co m*/
     * @param ctx
     * @throws VictimsException
     */
    private void updateDatabase(ExecutionContext context) throws VictimsException {
        VictimsDBInterface db = context.getDatabase();
        PrintStream log = context.getLog();
    
        Date updated = db.lastUpdated();
    
        // update: auto
        if (context.updateAlways()) {
            log.println("Updating database");
            db.synchronize();
        } else if (context.updateDaily()) { // update: daily
            Date today = new Date();
            SimpleDateFormat cmp = new SimpleDateFormat("yyyyMMdd");
            boolean updatedToday = cmp.format(today).equals(cmp.format(updated));
    
            if (!updatedToday) {
                log.println("Updating database");
                db.synchronize();
            } else {
                log.println("Database last updated: " + updated.toString());
            }
        } else { // update: disabled
            log.println("Database synchronization disabled.");
        }
    }
    

    From source file:eu.europeana.uim.plugin.solr.service.SolrWorkflowPlugin.java

    @Override
    public boolean process(MetaDataRecord<I> mdr, ExecutionContext<MetaDataRecord<I>, I> context)
            throws IngestionPluginFailedException, CorruptedDatasetException {
        mdr.deleteValues(EuropeanaModelRegistry.EDMDEREFERENCEDRECORD);
    
        String overrideChecks = context.getProperties().getProperty(OVERRIDECHECKS);
        boolean check = false;
        if (StringUtils.isNotEmpty(overrideChecks)) {
            check = Boolean.parseBoolean(overrideChecks);
        }/*from   ww  w  . jav a 2s.co m*/
        if (StringUtils.isNotEmpty(context.getProperties().getProperty(CLEARCACHE))) {
            if (Boolean.parseBoolean(context.getProperties().getProperty(CLEARCACHE))) {
                OsgiExtractor.clearCache();
                VocMemCache.clearCache(solrWorkflowService);
            }
        }
        SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd HH:mm:ss Z yyyy", Locale.US);
        try {
    
            Date updateDate = sdf.parse((mdr.getValues(EuropeanaModelRegistry.UIMUPDATEDDATE).size() > 0)
                    ? mdr.getValues(EuropeanaModelRegistry.UIMUPDATEDDATE).get(0)
                    : new Date(0).toString());
            Date ingestionDate = new Date(context.getValue(date));
    
            if (updateDate.after(ingestionDate) || updateDate.toString().equals(ingestionDate.toString())
                    || check) {
                if (mdr.getValues(EuropeanaModelRegistry.STATUS).size() == 0
                        || !mdr.getValues(EuropeanaModelRegistry.STATUS).get(0).equals(Status.DELETED)) {
                    try {
    
                        String value = mdr.getValues(EuropeanaModelRegistry.EDMRECORD).get(0);
                        IUnmarshallingContext uctx = bfact.createUnmarshallingContext();
                        IMarshallingContext marshallingContext = bfact.createMarshallingContext();
                        marshallingContext.setIndent(2);
                        RDF rdf = (RDF) uctx.unmarshalDocument(new StringReader(value));
                        RDF rdfCopy = clone(rdf);
                        if (rdf.getAgentList() != null) {
                            for (AgentType agent : rdf.getAgentList()) {
                                dereferenceAgent(rdfCopy, agent);
                            }
                        }
                        if (rdf.getConceptList() != null) {
                            for (Concept concept : rdf.getConceptList()) {
                                dereferenceConcept(rdfCopy, concept);
                            }
                        }
    
                        if (rdf.getPlaceList() != null) {
                            for (PlaceType place : rdf.getPlaceList()) {
                                dereferencePlace(rdfCopy, place);
                            }
                        }
    
                        for (ProxyType proxy : rdf.getProxyList()) {
                            if (proxy.getEuropeanaProxy() == null
                                    || !proxy.getEuropeanaProxy().isEuropeanaProxy()) {
                                if (StringUtils
                                        .isNotEmpty(context.getProperties().getProperty(LIBRARYOFCONGRESS))) {
                                    if (Boolean
                                            .parseBoolean(context.getProperties().getProperty(LIBRARYOFCONGRESS))) {
                                        for (Choice choice : proxy.getChoiceList()) {
                                            if (choice.ifSubject()) {
                                                if (StringUtils.startsWith(choice.getSubject().getString(), "sh")
                                                        && StringUtils.isNumeric(StringUtils.substringAfter(
                                                                choice.getSubject().getString(), "sh"))) {
                                                    Subject sbj = choice.getSubject();
                                                    String subject = "http://data.europeana.eu/concept/loc/"
                                                            + sbj.getString();
                                                    ResourceOrLiteralType.Resource rs = new ResourceOrLiteralType.Resource();
                                                    rs.setResource(subject);
                                                    Subject sbjNrm = new Subject();
                                                    sbjNrm.setResource(rs);
                                                    sbjNrm.setLang(new ResourceOrLiteralType.Lang());
                                                    sbjNrm.setString("");
                                                    choice.setSubject(sbjNrm);
                                                }
                                            }
                                        }
                                    }
                                }
                                dereferenceProxy(rdfCopy, proxy);
                            }
                        }
    
                        if (rdf.getTimeSpanList() != null) {
                            for (TimeSpanType timespan : rdf.getTimeSpanList()) {
                                dereferenceTimespan(rdfCopy, timespan);
                            }
                        }
                        if (rdf.getWebResourceList() != null) {
                            for (WebResourceType webresource : rdf.getWebResourceList()) {
                                dereferenceWebResource(rdfCopy, webresource);
                            }
                        }
    
                        ByteArrayOutputStream out = new ByteArrayOutputStream();
                        RDF rdfFinal = cleanRDF(rdfCopy);
    
                        ProxyType europeanaProxy = new ProxyType();
                        EuropeanaProxy prx = new EuropeanaProxy();
                        prx.setEuropeanaProxy(true);
                        europeanaProxy.setEuropeanaProxy(prx);
                        List<String> years = new ArrayList<String>();
                        for (ProxyType proxy : rdfFinal.getProxyList()) {
                            years.addAll(new EuropeanaDateUtils().createEuropeanaYears(proxy));
                            europeanaProxy.setType(proxy.getType());
                        }
                        List<Year> yearList = new ArrayList<Year>();
                        for (String year : years) {
                            Year yearObj = new Year();
                            Lang lang = new Lang();
                            lang.setLang("def");
                            yearObj.setLang(lang);
                            yearObj.setString(year);
                            yearList.add(yearObj);
                        }
                        europeanaProxy.setYearList(yearList);
                        for (ProxyType proxy : rdfFinal.getProxyList()) {
                            if (proxy != null && proxy.getEuropeanaProxy() != null
                                    && proxy.getEuropeanaProxy().isEuropeanaProxy()) {
                                rdfFinal.getProxyList().remove(proxy);
                            }
                        }
                        rdfFinal.getProxyList().add(europeanaProxy);
    
                        marshallingContext.marshalDocument(rdfFinal, "UTF-8", null, out);
                        String der = out.toString("UTF-8");
    
                        mdr.addValue(EuropeanaModelRegistry.EDMDEREFERENCEDRECORD, der);
                        return true;
    
                    } catch (JiBXException e) {
                        e.printStackTrace();
                        context.getLoggingEngine().logFailed(Level.SEVERE, this, e,
                                "JiBX unmarshalling has failed with the following error: " + e.getMessage());
    
                    } catch (MalformedURLException e) {
                        if (logEngine != null) {
                            logEngine.logFailed(Level.SEVERE, this, e, e.getMessage());
                        }
                        log.log(Level.SEVERE, "Error: " + e.getMessage());
                        e.printStackTrace();
                    } catch (IOException e) {
                        if (logEngine != null) {
                            logEngine.logFailed(Level.SEVERE, this, e, e.getMessage());
                        }
                        log.log(Level.SEVERE, "Error: " + e.getMessage());
                        e.printStackTrace();
                    } catch (SecurityException e) {
                        if (logEngine != null) {
                            logEngine.logFailed(Level.SEVERE, this, e, e.getMessage());
                        }
                        log.log(Level.SEVERE, "Error: " + e.getMessage());
                        e.printStackTrace();
                    } catch (IllegalArgumentException e) {
                        if (logEngine != null) {
                            logEngine.logFailed(Level.SEVERE, this, e, e.getMessage());
                        }
                        log.log(Level.SEVERE, "Error: " + e.getMessage());
                        e.printStackTrace();
                    } catch (NoSuchMethodException e) {
                        if (logEngine != null) {
                            logEngine.logFailed(Level.SEVERE, this, e, e.getMessage());
                        }
                        log.log(Level.SEVERE, "Error: " + e.getMessage());
                        e.printStackTrace();
                    } catch (IllegalAccessException e) {
                        if (logEngine != null) {
                            logEngine.logFailed(Level.SEVERE, this, e, e.getMessage());
                        }
                        log.log(Level.SEVERE, "Error: " + e.getMessage());
                        e.printStackTrace();
                    } catch (InvocationTargetException e) {
                        if (logEngine != null) {
                            logEngine.logFailed(Level.SEVERE, this, e, e.getMessage());
                        }
                        log.log(Level.SEVERE, "Error: " + e.getMessage());
                        e.printStackTrace();
                    } catch (InstantiationException e) {
                        if (logEngine != null) {
                            logEngine.logFailed(Level.SEVERE, this, e, e.getMessage());
                        }
                        log.log(Level.SEVERE, "Error: " + e.getMessage());
    
                        e.printStackTrace();
                    }
    
                }
            }
        } catch (Exception e) {
            if (logEngine != null) {
                logEngine.logFailed(Level.SEVERE, this, e, e.getMessage());
            }
            e.printStackTrace();
        }
        return false;
    }
    

    From source file:ch.ksfx.web.services.chart.ObservationChartGenerator.java

    public JFreeChart generateChart(TimeSeries timeSeries, Date startDate, Date endDate) {
        List<Observation> observations = observationDAO.queryObservationsSparse(timeSeries.getId().intValue(),
                startDate, endDate);/*from  w w  w .  j  a  va 2 s  .  c o  m*/
    
        if (observations == null || observations.size() == 0 || observations.isEmpty()) {
            Observation o = observationDAO.getLastObservationForTimeSeriesId(timeSeries.getId().intValue());
            Long diffInMillis = endDate.getTime() - startDate.getTime();
            startDate = DateUtils.addMilliseconds(o.getObservationTime(), diffInMillis.intValue() * -1);
    
            System.out.println("[GRAPH] Found 0 Observations trying new query (" + timeSeries.getId() + ") "
                    + "Startdate: " + startDate.toString() + " End date: " + endDate.toString());
            observations = observationDAO.queryObservationsSparse(timeSeries.getId().intValue(), startDate,
                    DateUtils.addMilliseconds(o.getObservationTime(), 1000));
        }
    
        System.out
                .println("[GRAPH] Observations size: " + observations.size() + " for (" + timeSeries.getId() + ")");
    
        //assetPrices = simplifyAssetPrices(assetPrices);
    
        TimePeriodValues assetPriceTimePeriodValues = new TimePeriodValues(timeSeries.getName());
        TimePeriodValuesCollection dataset = new TimePeriodValuesCollection();
    
        for (Observation o : observations) {
            assetPriceTimePeriodValues.add(new SimpleTimePeriod(o.getObservationTime(), o.getObservationTime()),
                    Double.parseDouble(o.getScalarValue()));
        }
    
        dataset.addSeries(assetPriceTimePeriodValues);
    
        JFreeChart jFreeChart = ChartFactory.createXYLineChart("Performance", "Time", "Value", dataset,
                PlotOrientation.VERTICAL, true, false, false);
    
        setRange(jFreeChart, observations);
    
        return jFreeChart;
    }
    

    From source file:org.ejbca.core.protocol.cmp.CrmfRequestMessage.java

    @Override
    public Date getRequestValidityNotAfter() {
        Date ret = null;
        final CertTemplate templ = getReq().getCertReq().getCertTemplate();
        final OptionalValidity val = templ.getValidity();
        if (val != null) {
            DERSequence valSeq = (DERSequence) val.toASN1Primitive();
            ASN1Encodable[] asn1a = valSeq.toArray();
            final Time time = Time.getInstance((ASN1TaggedObject) asn1a[1], true);
            if (time != null) {
                ret = time.getDate();//  w w  w. j a  va2 s.c  om
            }
        }
        if (log.isDebugEnabled()) {
            log.debug("Request validity notAfter is: " + (ret == null ? "null" : ret.toString()));
        }
        return ret;
    }
    

    From source file:org.ejbca.core.protocol.cmp.CrmfRequestMessage.java

    @Override
    public Date getRequestValidityNotBefore() {
        Date ret = null;
        final CertTemplate templ = getReq().getCertReq().getCertTemplate();
        final OptionalValidity val = templ.getValidity();
        if (val != null) {
            DERSequence valSeq = (DERSequence) val.toASN1Primitive();
            ASN1Encodable[] asn1a = valSeq.toArray();
            final Time time = Time.getInstance((ASN1TaggedObject) asn1a[0], true);
            if (time != null) {
                ret = time.getDate();//www .  j  ava  2s. c  o  m
            }
        }
        if (log.isDebugEnabled()) {
            log.debug("Request validity notBefore is: " + (ret == null ? "null" : ret.toString()));
        }
        return ret;
    }
    

    From source file:io.lqd.sdk.Liquid.java

    private void newSession(boolean runInCurrentThread) {
        final Date now = UniqueTime.newDate();
        LQLog.infoVerbose("Open Session: " + now.toString());
        Runnable newSessionRunnable = new Runnable() {
            @Override/* ww w.  j  a v  a  2 s.co m*/
            public void run() {
                mCurrentSession = new LQSession(mSessionTimeout, now);
                track("_startSession", null, now);
            }
        };
        if (runInCurrentThread) {
            newSessionRunnable.run();
        } else {
            mQueue.execute(newSessionRunnable);
        }
    }
    

    From source file:gov.noaa.pfel.erddap.dataset.EDDGridFromMergeIRFiles.java

    /**
     * This gets source axis values from one file.
     *
     * @param fileDir//www.j a  v  a 2  s. c  o m
     * @param fileName
     * @param sourceAxisNames the names of the desired source axis variables.
     *   If there is a special axis0, this will not include axis0's name.
     * @return a PrimitiveArray[] with the results (with the requested
     *   sourceDataTypes). It needn't set sourceGlobalAttributes or
     *   sourceDataAttributes (but see getSourceMetadata).
     * @throws Throwable if trouble (e.g., invalid file). If there is trouble,
     * this doesn't call addBadFile or requestReloadASAP().
     */
    public PrimitiveArray[] lowGetSourceAxisValues(String fileDir, String fileName, StringArray sourceAxisNames)
            throws Throwable {
    
        String getWhat = "";
    
        try {
            PrimitiveArray[] avPa = new PrimitiveArray[sourceAxisNames.size()];
    
            for (int avi = 0; avi < sourceAxisNames.size(); avi++) {
                String avName = sourceAxisNames.get(avi);
                getWhat = "axisValues for variable=" + avName;
    
                switch (avName) {
                case "longitude":
                    FloatArray lonBounds = new FloatArray(NLON, true);
                    float lon = 0.0182f;
                    for (int i = 0; i < NLON; i++) {
                        lonBounds.setFloat(i, lon);
                        lon += SLON;
                    }
                    avPa[avi] = lonBounds;
                    break;
                case "latitude":
                    FloatArray latBounds = new FloatArray(NLAT, true);
                    float lat = -59.982f;
                    for (int i = 0; i < NLAT; i++) {
                        latBounds.setFloat(i, lat);
                        lat += SLAT;
                    }
                    avPa[avi] = latBounds;
                    break;
                case "time": {
                    if (reallyVerbose)
                        String2.log("case time with " + fileName);
                    String sdate = File2.getNameNoExtension(fileName).replaceAll("merg_", "")
                            .replaceAll("_4km-pixel", "");
                    if (reallyVerbose)
                        String2.log("date = " + sdate + " (" + sdate.length() + ")");
    
                    if (sdate.length() != 10)
                        throw new RuntimeException(
                                "File name (" + fileName + ") must contain a date encoded as 10 characters.");
    
                    //format fdjksdfljk_2014010102
                    String year = sdate.substring(0, 4);
                    String month = sdate.substring(4, 6);
                    String day = sdate.substring(6, 8);
                    String hour = sdate.substring(8, 10);
    
                    java.text.SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
                    sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
                    String fileTime = month + "/" + day + "/" + year + " " + hour + ":00:00";
                    Date date = sdf.parse(fileTime);
    
                    //calculate bounds 
                    long d0 = date.getTime() / 1000;
                    long d1 = d0 + 1800;
    
                    //log
                    getWhat += "fileTime = " + fileTime + " --> date = \"" + date.toString() + "\" (d0=" + d0
                            + ", d1=" + d1 + ")";
                    if (reallyVerbose)
                        String2.log(getWhat);
    
                    //set result
                    DoubleArray ret = new DoubleArray(2, true);
                    ret.set(0, d0);
                    ret.set(1, d1);
    
                    avPa[avi] = ret;
                }
                    break;
                default:
                    throw new Exception("case : " + avName);
                }
            }
            return avPa;
    
        } catch (Throwable t) {
            throw new RuntimeException("Error in EDDGridFromMergeIRFiles.getSourceAxisValues" + "\nwhile getting "
                    + getWhat + "\nfrom " + fileDir + fileName + "\nCause: " + MustBe.throwableToShortString(t), t);
        }
    }
    

    From source file:com.cloud.network.security.NetworkGroupManagerImpl.java

    public void cleanupFinishedWork() {
        Date before = new Date(System.currentTimeMillis() - 24 * 3600 * 1000l);
        int numDeleted = _workDao.deleteFinishedWork(before);
        if (numDeleted > 0) {
            s_logger.info("Network Group Work cleanup deleted " + numDeleted + " finished work items older than "
                    + before.toString());
        }//  w w w  .  ja v a 2 s  .  c o m
    
    }
    

    From source file:org.dvbviewer.controller.ui.fragments.ChannelList.java

    /**
     * Cursor to timer./*from w ww  .j a  v  a2  s .c  o  m*/
     *
     * @param c the c
     * @return the timer
     * @author RayBa
     * @date 07.04.2013
     */
    private Timer cursorToTimer(Cursor c) {
        String name = c.getString(c.getColumnIndex(ChannelTbl.NAME));
        long channelID = c.getLong(c.getColumnIndex(ChannelTbl._ID));
        String epgTitle = !c.isNull(c.getColumnIndex(EpgTbl.TITLE)) ? c.getString(c.getColumnIndex(EpgTbl.TITLE))
                : name;
        long epgStart = c.getLong(c.getColumnIndex(EpgTbl.START));
        long epgEnd = c.getLong(c.getColumnIndex(EpgTbl.END));
        DVBViewerPreferences prefs = new DVBViewerPreferences(getSherlockActivity());
        int epgBefore = prefs.getPrefs().getInt(DVBViewerPreferences.KEY_TIMER_TIME_BEFORE, 5);
        int epgAfter = prefs.getPrefs().getInt(DVBViewerPreferences.KEY_TIMER_TIME_AFTER, 5);
        Date start = epgStart > 0 ? new Date(epgStart) : new Date();
        Date end = epgEnd > 0 ? new Date(epgEnd) : new Date(start.getTime() + (1000 * 60 * 120));
        Log.i(ChannelList.class.getSimpleName(), "start: " + start.toString());
        Log.i(ChannelList.class.getSimpleName(), "end: " + end.toString());
        start = DateUtils.addMinutes(start, 0 - epgBefore);
        end = DateUtils.addMinutes(end, epgAfter);
        Timer timer = new Timer();
        timer.setTitle(epgTitle);
        timer.setChannelId(channelID);
        timer.setChannelName(name);
        timer.setStart(start);
        timer.setEnd(end);
        timer.setTimerAction(prefs.getPrefs().getInt(DVBViewerPreferences.KEY_TIMER_DEF_AFTER_RECORD, 0));
        return timer;
    }
    

    From source file:pl.bcichecki.rms.client.android.fragments.EventsListFragment.java

    private void downloadData() {
        Log.d(TAG, "Downloading events list...");
    
        if (!AppUtils.checkInternetConnection(getActivity())) {
            Log.d(TAG, "There is NO network connected!");
            return;//from www  .  j  ava 2 s  .  c o  m
        }
    
        final Date now = new Date();
        final Date from = DateUtils.round(DateUtils.addDays(now, DAYS_BACK - 1), Calendar.DAY_OF_MONTH);
        final Date till = DateUtils.round(DateUtils.addDays(now, DAYS_AHEAD + 1), Calendar.DAY_OF_MONTH);
    
        eventsRestClient.getAllEvents(from, till,
                new GsonHttpResponseHandler<List<Event>>(new TypeToken<List<Event>>() {
                }.getType(), true) {
    
                    @Override
                    public void onFailure(Throwable error, String content) {
                        Log.d(TAG, "Retrieving events from " + from.toString() + " till " + till.toString()
                                + " failed. [error=" + error + ", content=" + content + "]");
                        if (error instanceof HttpResponseException) {
                            if (((HttpResponseException) error).getStatusCode() == HttpStatus.SC_UNAUTHORIZED) {
                                AppUtils.showCenteredToast(getActivity(),
                                        R.string.general_unathorized_error_message_title, Toast.LENGTH_LONG);
                            } else {
                                AppUtils.showCenteredToast(getActivity(),
                                        R.string.general_unknown_error_message_title, Toast.LENGTH_LONG);
                            }
                        } else {
                            AppUtils.showCenteredToast(getActivity(), R.string.general_unknown_error_message_title,
                                    Toast.LENGTH_LONG);
                        }
                    }
    
                    @Override
                    public void onFinish() {
                        eventsListAdapter.refresh();
                        hideLoadingMessage();
                        Log.d(TAG, "Retrieving events finished.");
                    }
    
                    @Override
                    public void onStart() {
                        Log.d(TAG, "Retrieving events from " + from.toString() + " till " + till.toString()
                                + " started.");
                        showLoadingMessage();
                        events.clear();
                    }
    
                    @Override
                    public void onSuccess(int statusCode, List<Event> object) {
                        Log.d(TAG, "Retrieving events from " + from.toString() + " till " + till.toString()
                                + " successful. Retrieved " + object.size() + " objects.");
                        events.addAll(object);
                    }
                });
    }