How to get Timestamp with AM/PM in java
datetime, java
Solution
Why create a timestamp ? When you can just :
SimpleDateFormat sfdate = new SimpleDateFormat("MM/dd/yyy HH:mm:ss a");
Date date = new Date();
date = sfdate.parse(dateString);
System.out.println(sfdate.format(date) );
Output:
10/10/10 11:23:29 AM
Problem
I have a date as String , which needs to be converted in to Time Stamp with AM/PM . I tried the below way, I'm getting the proper date format but didn't get in AM/PM. Can any one please help ? code Snippet: ``` String dateString = "10/10/2010 11:23:29 AM"; SimpleDateFormat sfdate = new SimpleDateFormat("MM/dd/yyy HH:mm:ss a"); Date date = new Date(); date = sfdate.parse(dateString); System.out.println(new Timestamp(date.getTime())); ``` Which gives me the output as below : ``` 2010-10-10 11:23:29.0 ``` But I needs it like this ``` 2010-10-10 11:23:29.00000000 AM ``` Kindly help me please.