I am converting String to Timestamp but output format has extra '0'.
Below is the code.
Code:
import java.math.BigDecimal;
import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
public class StringToTimeStamp {
public static void main(String[] args) {
String date = "2017-01-01T00:00:00.000-05:00";
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
try {
java.util.Date parsedDate = dateFormat.parse(date);
System.out.println(parsedDate);
Timestamp time = new Timestamp(parsedDate.getTime());
System.out.println(time);
} catch (ParseException e) {
e.printStackTrace();
}
}
}
Output
Sun Jan 01 00:00:00 IST 2017
2017-01-01 00:00:00.0
Expected output
Sun Jan 01 00:00:00 IST 2017
2017-01-01 00:00:00
I am not able to understand why extra '0' is there in output?
JDK version : 1.8.0_191
EDIT
I tried formatting my timestamp instance like this :
System.out.println(dateFormat.format(time));
It gave below output :
Sun Jan 01 00:00:00 IST 2017
2017-01-01T00:00:00
It removed '0' but added 'T'.