Conversion between date format (dates) and long types _date

Source: Internet
Author: User

Indexing and searching for dates in Lucenen

Declare
private date[] dates = {};
Storing dates in an array in a fixed format
private void Setdates () {
	SimpleDateFormat sdf = new SimpleDateFormat ("Yyyy-mm-dd");
	dates = new Date[ids.length];
	try {
		Dates[0] = Sdf.parse ("2010-02-19");
		DATES[1] = Sdf.parse ("2012-01-11");
		DATES[2] = Sdf.parse ("2011-09-19");
		DATES[3] = Sdf.parse ("2010-12-22");
		DATES[4] = Sdf.parse ("2012-01-01");
	} catch (ParseException e) {
		e.printstacktrace ();
	}
}
When indexing, it is not necessary to make the date segmentation and weighted values, and other operations
Doc.add (New Numericfield ("date", Field.store.yes,true). Setlongvalue (Dates[i].gettime ());
where SD is Scorcedoc
Search by ID, get ID corresponding to document
document DOC = Searcher.doc (sd.doc);
Converts a long type of date to date type
//from doc to get the value of the index in the date field to hold
Long num = long.valueof (doc.get ("date"));
SimpleDateFormat sdf1 = new SimpleDateFormat ("Yyyy-mm-dd");
Convert a long to date type
java.util.Date dt = new Date (num) by using the constructor function;
Formats the date type
String sdatetime = sdf1.format (DT);


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.