Reputation: 31
Can someone please tell me how I can extract the date and time from this? I'm a java nube! :-)
Its being sent as XML and when I read the node its in the following format:
For me objDeliveryRoute.getStartTime() is a date in the following format:
yyyy-MM-ddThh:mm:nn (T in this is for Tango).
Example would be:
2012-04-24T18:41:00
This needs to find a home in an MSSQL Server 2008 db.
Here's the code snippet that I'm suffering with:
mydatetime = new java.sql.Timestamp(objDeliveryRoute.getStartTime().toGregorianCalendar().getTime().getTime());
Upvotes: 0
Views: 318
Reputation:
Use SimpleDateFormat class from standard JavaSDK.
Check this code snippet. It makes a java.util.Date instance from string you provided:
DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
String myDateString = "2012-04-24T18:41:00";
java.util.Date myDate = df.parse(myDateString);
To compose java.sql.Date instance, do the following according to the aforecited code snippet:
java.sql.Date sqlDate = new java.sql.Date(myDate.getTime());
Upvotes: 1