While reading a date column from a .csv file which is of 'dd/mm/yyyy hh:mi:ss am' format through javacode. I declared the variable as Long in javacode. how to parse in the javacode.
1 Answer
SimpleDateFormat df1 = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss a"); Date d = df1.parse(inputString); long timeInMillis = d.getTime(); Java API reference: http://java.sun.com/javase/6/docs/api/java/text/SimpleDateFormat.html
6 Comments
St.Shadow
For complete answer post link to API javadoc .
St.Shadow
Better, but why 1.4, but not 1.6?
jyothi
status.setStateChange((Date) df1.parse(results.getString("STATECHANGE"))); It is getting the result from a .csv file where the format of the string is dd/mm/yyyy hh:mm:ss am/pm . But at the above point of code still it is showing the cast error
BalusC
@jyothi: Do not import
java.sql.Date. Import java.util.Date. Read the linked Java API reference for more details what exactly parse() method returns.jyothi
Date stateChange = null ; public void setStateChange(Date stateChange) { this.stateChange = stateChange; } while reading from the result set:(Result Got the result from a csv file where Statechange is a date column of format mm/dd/yyyy hh:mi:ss am. status.setStateChange((Date) sdf.parse(results.getString("STATECHANGE"))); It is showing a cast error. at the above statement
|