Parsing string, date and time from a user defined sentence in android application

  • Replies:3
  • Answered
  • Forum posts: 8

Feb 24, 2016, 8:27:42 AM via Website

I am developing an android application in which i want to parser the date, time and string that is what Natty (Date Parser) do is exactly needed for me. I have tried in eclipse IDE. I have manually added the following jar files.


And i have followed the instructions given in Natty website. That is in POM file,i have added the dependency as


and added the following in main java file.

import com.joestelmach.natty.*;
Parser parser = new Parser();
List groups = parser.parse("the day before next thursday");
for(DateGroup group:groups) {
List dates = group.getDates();
int line = group.getLine();
int column = group.getPosition();
String matchingValue = group.getText();
String syntaxTree = group.getSyntaxTree().toStringTree();
Map parseMap = group.getParseLocations();
boolean isRecurreing = group.isRecurring();
Date recursUntil = group.getRecursUntil();

I have imported three libraries.

import java.util.Date;
import java.util.List;
import java.util.Map;

Now i am getting an error in this line.

for(DateGroup group:groups)

Error: Type mismatch: cannot convert from element type Object to DateGroup.

Please suggest me some solutions for this.

I have added the Parser class under onCreateOptionsMenu function.

Or please suggest me some other solutions for me to parse the date,time and string from a sentence. For example, consider the following sentence "Lets go for lunch on July 17th 2016 at 1 pm", from this i need to extract Date:17th July 2016, time 1 pm and string : Lets go for lunch.

  • Forum posts: 12

Feb 26, 2016, 12:49:34 AM via Website

Parser's parse method returns:


In your example above you've dropped the type information (I see the example on natty's website does the same; the compiler they were using must ignore the implicit type cast there). The following should work (note - not tested):

List<DateGroup> groups = parser.parse("the day before next thursday");
for(DateGroup group:groups) {

— modified on Feb 26, 2016, 12:50:51 AM

Vishnupriya Raju

  • Forum posts: 8

Feb 26, 2016, 6:13:44 AM via Website

Thank you so much for your suitable answer and timely help.

I am wondering if you can, please give suggestion for the following warning.

In the same coding i am getting the warning as "List is a raw type. References to generic type List should be parameterized"

And also i want to display the date in Edittext.

  • Forum posts: 8

Feb 26, 2016, 6:32:56 AM via Website

Thank you so much for effort. I got my application worked.