How to convert a string to Date and then add it to excel using jexcel api
I am currently reading a CSV file. I have to extract the dates from it and add them to excel file in dd-MM-yy
format. I am faced with two problems.
- I am using
String.split(delim)
where,delim="[,]"
. I am getting the date inyyyy-MM-dd
format. - I am not able to convert the string into a da开发者_StackOverflowte format and then add them to excel file. I tried using
DateFormat
but error saysDateformat is abstract
.
Here is the code
dtformat=new SimpleDateFormat("dd-MM-yy");
datenow=dtformat.parse(stringDate);//datenow is what i want to add to add.
datecell=new DateTime(tokenNumber, lineNumber, datenow);
sheet.addCell(datecell);
When I open the excel file, I get wild values.
Please help.Thanks in advance
Google is your friend.
To parse date:
DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
Date date = (Date)formatter.parse("2011 02 07");
To write date:
DateFormat customDateFormat = new DateFormat ("dd-MM-yy");
WritableCellFormat dateFormat = new WritableCellFormat (customDateFormat);
sheet.addCell(new DateTime(/* date */, dateFormat));
精彩评论