Example usage for java.util Date getTime

List of usage examples for java.util Date getTime

Introduction

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

Prototype

public long getTime() 

Source Link

Document

Returns the number of milliseconds since January 1, 1970, 00:00:00 GMT represented by this Date object.

Usage

From source file:Main.java

public static long parseFeedDate(String date) {
    SimpleDateFormat formatter;//from   w  w w . ja  v  a2 s  . c om
    if (date.contains(" - ")) {
        date = date.split(" - ")[0].trim();
    }
    formatter = new SimpleDateFormat("d. MMMM yyyy");

    Date d = null;
    try {
        d = formatter.parse(date);
    } catch (ParseException e) {
        e.printStackTrace();
    }
    return d.getTime();
}

From source file:Main.java

/**
 * @param currentDate The new date value
 * @param lastUpdateDate The last time the data was updated
 * @param seconds desired duration between updates
 * @return true if enough time has elapsed or if the dates are null. False otherwise.
 *///from   w  ww  .  j a va2 s. c  o  m
public static boolean shouldUpdate(Date currentDate, Date lastUpdateDate, long seconds) {
    if (currentDate == null || lastUpdateDate == null) {
        return true;
    }

    long diff = currentDate.getTime() - lastUpdateDate.getTime();
    return (diff / 1000 % 60) > seconds;
}

From source file:com.hengyi.japp.execution.Util.java

public static long getMilliSecondsDelay(Date date) {
    long delay = date.getTime() - System.currentTimeMillis();
    return delay < 0 ? 0 : delay;
}

From source file:Main.java

public static Long dateStrToLong(String str) {
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
    Date addTime = null;
    try {//from  www . j a  va2  s  .c om
        addTime = dateFormat.parse(str);
    } catch (ParseException e) {
        e.printStackTrace();
    }
    return addTime.getTime();
}

From source file:de.dkt.eservices.elucene.indexmanagement.SearchFiles.java

/**
 * Searches a query against a field of an index and return hitsToReturn documents.
 * @param index index where to search for the query text
 * @param field document field against what to match the query
 * @param queryString text of the input query
 * @param hitsToReturn number of documents to be returned
 * @return JSON format string containing the results information and content
 * @throws ExternalServiceFailedException
 *//*  ww  w . ja v a 2  s  .  co m*/
public static JSONObject search(String index, String sFields, String sAnalyzers, String queryType,
        String queryString, String language, int hitsToReturn) throws ExternalServiceFailedException {
    try {
        //         System.out.println(index+"__"+sFields+"__"+sAnalyzers+"__"+queryType+"__"+language+"__"+hitsToReturn);
        //         System.out.println(indexDirectory);
        Date start = new Date();

        File f = FileFactory.generateFileInstance(indexDirectory + index);
        if (f == null || !f.exists()) {
            throw new ExternalServiceFailedException(
                    "Specified index [" + indexDirectory + index + "] does not exists.");
        }
        logger.info("Searching in folder: " + f.getAbsolutePath());
        Directory dir = FSDirectory.open(f);
        IndexReader reader = DirectoryReader.open(dir);
        IndexSearcher searcher = new IndexSearcher(reader);

        //         System.out.println(reader.docFreq(new Term("content", "madrid")));

        Document doc = reader.document(0);
        //         System.out.println(reader.numDocs());
        //         System.out.println(doc);

        String[] fields = sFields.split(";");
        String[] analyzers = sAnalyzers.split(";");
        if (fields.length != analyzers.length) {
            logger.error("The number of fields and analyzers is different");
            throw new BadRequestException("The number of fields and analyzers is different");
        }

        //System.out.println("CHECK IF THE QUERY IS WORKING PROPERLY: "+queryString);
        Query query = OwnQueryParser.parseQuery(queryType, queryString, fields, analyzers, language);

        //System.out.println("\t QUERY: "+query);

        TopDocs results = searcher.search(query, hitsToReturn);

        Explanation exp = searcher.explain(query, 0);
        //         System.out.println("EXPLANATION: "+exp);

        //         System.out.println("TOTAL HITS: " + results.totalHits);

        Date end = new Date();
        logger.info("Time: " + (end.getTime() - start.getTime()) + "ms");
        //         System.out.println("Time: "+(end.getTime()-start.getTime())+"ms");

        JSONObject resultModel = JSONLuceneResultConverter.convertResults(query, searcher, results);
        reader.close();
        return resultModel;
    } catch (IOException e) {
        e.printStackTrace();
        throw new ExternalServiceFailedException("IOException with message: " + e.getMessage());
    }
}

From source file:Main.java

public static long getStringToDate(String time, String format) {
    if (format != null) {
        sf = new SimpleDateFormat(format);
    } else {//from  www . ja v a  2  s .  c  om
        sf = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss");
    }
    Date date = new Date();
    try {
        date = sf.parse(time);
    } catch (ParseException e) {
        e.printStackTrace();
    }
    return date.getTime();
}

From source file:com.eas.client.reports.JSDynaBean.java

public static double convertDateToExcelDate(Date aValue, int aTimezoneOffset) {
    return ((double) (aValue.getTime() - aTimezoneOffset * 60 * 1000) / 86400000) + 25569;
}

From source file:de.blizzy.documentr.TestUtil.java

public static void assertSecondsAgo(Date d, int seconds) {
    long time = d.getTime();
    long now = System.currentTimeMillis();
    assertTrue((now - time) <= (seconds * 1000L));
}

From source file:edu.usu.sdl.openstorefront.common.util.TimeUtil.java

/**
 * Get the start of the day passed in/*w  w w.j  a va2  s. co m*/
 *
 * @param date
 * @return beginning of day or null if date was null
 */
public static Date beginningOfDay(Date date) {
    if (date != null) {
        Instant instant = Instant.ofEpochMilli(date.getTime()).truncatedTo(ChronoUnit.DAYS);
        return new Date(instant.toEpochMilli());
    }
    return date;
}

From source file:info.magnolia.cms.util.DateUtil.java

/**
 * Convert a local date time to a UTC calendar
 *///from  www .  j a  va  2 s  .  c  om
public static Calendar getUTCCalendarFromLocalDate(Date date) {
    Calendar instance = Calendar.getInstance(UTC_TIME_ZONE);
    instance.setTimeInMillis(date.getTime());
    return instance;
}