I have a CSV file with a date string column. I want to spend the CSV data into mysql.
In CSV has a String
: "Sun Oct 05 20:59:57 BRT 2014" and I want to convert to DateTime
.
How do I do this?
I have a CSV file with a date string column. I want to spend the CSV data into mysql.
In CSV has a String
: "Sun Oct 05 20:59:57 BRT 2014" and I want to convert to DateTime
.
How do I do this?
You should use this DateTimeFormat
EEE MMM dd HH:mm:ss z yyyy
And now you should do this :
String string = "Sun Oct 05 20:59:57 BRT 2014";
DateTimeFormatter formatter = DateTimeFormat.forPattern("EEE MMM dd HH:mm:ss z yyyy");
Date dt = formatter.parse(string); //if you want to use DateTime do it DateTime dt = formatter.parse(string);
System.out.println(" Date " + datetime.toString());
First of all include those imports:
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
Then your code should looks like as follows :
String string = "Sun Oct 05 20:59:57 BRT 2014";
SimpleDateFormat formatter = new SimpleDateFormat("EEE MMM dd HH:mm:ss z yyyy");
java.sql.Timestamp datetime = new Timestamp(formatter.parse(string).getTime());
System.out.println("DateTime: " + datetime.toString());
To use DateTime
you should check this Question
You should use this code:
DateTimeFormatter formatter = DateTimeFormat.forPattern("dd/MM/yyyy HH:mm:ss");
DateTime dt = formatter.parseDateTime(string);
Try DateTimeFormat
DateTimeFormatter formatter = DateTimeFormat.forPattern("EEE MMM dd HH:mm:ss z yyyy");
DateTime dt = formatter.parseDateTime(string);
Here is similar question.