Using Univocity, how can I convert a date string value to a Date type in Java -


i'll parse column 0 in csv file particular datatype, in example date object.

the method below use parse csv file don't know how incorporate requirement.

import java.sql.date; public class data {      @parsed(index = 0)         private date date;     } }  public <t> list<t> convertfiletodata(file file, class<t> clazz) {      beanlistprocessor<t> rowprocessor = new beanlistprocessor<>(clazz);     csvparsersettings settings = new csvparsersettings();     settings.setprocessor(rowprocessor);     settings.setheaderextractionenabled(true);      csvparser parser = new csvparser(settings);     parser.parseall(file);      return rowprocessor.getbeans(); } 

all need define format(s) of date , set:

@format(formats = {"dd-mmm-yyyy", "yyyy-mm-dd"}) @parsed(index = 0)     private date date; } 

as suggestion, can replace lot of code using csvroutines class. try this:

list<t> beanlist = new csvroutines(settings).parseall(clazz, file); 

hope helps.


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -