| Author |
String to DATE
|
marys joseph
Greenhorn
Joined: May 14, 2004
Posts: 20
|
|
Hi, I am reading data from excel file and updating the sql table. When I read all the contents from excel file are in String format. How do I change the string into Date. For ex: String s ='3/31/2003' When I tried Date renew = new Date(s); it is not storing the correct date. I need to insert 3/31/2003 into the DB table. any suggestions? thanks,
|
 |
Blake Minghelli
Ranch Hand
Joined: Sep 13, 2002
Posts: 331
|
|
|
Take a look at the api docs for java.text.SimpleDateFormat. It provides the mechanism for converting strings into date objects and vice-versa
|
Blake Minghelli<br />SCWCD<br /> <br />"I'd put a quote here but I'm a non-conformist"
|
 |
Ko Ko Naing
Ranch Hand
Joined: Jun 08, 2002
Posts: 3178
|
|
The simplest way is... Cut your String s into month, day and year and use the GregorianCalendar(int year, int month, int dayOfMonth) Constructor to create a GregorianCalendar object... Later get a date instance from it and then do things with DB... Hope it helps...
|
Co-author of SCMAD Exam Guide, Author of JMADPlus
SCJP1.2, CCNA, SCWCD1.4, SCBCD1.3, SCMAD1.0, SCJA1.0, SCJP6.0
|
 |
Greg T Robertson
Ranch Hand
Joined: Nov 18, 2003
Posts: 91
|
|
|
GregorianCalendar is nice EXCEPT that you have to be very careful with getting Dates & Timestamps you can lose some hours (this can affect Dates too). I second the DateFormat classes.
|
 |
 |
|
|
subject: String to DATE
|
|
|