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
Post a Comment