1

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 1

4
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

Sign up to request clarification or add additional context in comments.

6 Comments

For complete answer post link to API javadoc .
Better, but why 1.4, but not 1.6?
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
@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.
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
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.