How to convert 'dd/mm/yyyy hh:mm:ss am/pm' to hh:mm:ss (without am or pm) in java?
33,416
Solution 1
SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss a", Locale.US);
Date date = format.parse("1/15/2014 9:57:03 AM");
format = new SimpleDateFormat("HH:mm:ss");
String dateString = format.format(date);
BTW, use Google next time
Solution 2
You should see this in the doc doc SimpleDateFormat
Related videos on Youtube
Author by
user3205610
Updated on July 05, 2022Comments
-
user3205610 almost 2 years
I want the convert the string like
1/15/2014 9:57:03 AM
or1/15/2014 5:49:39 PM
to9:57:03
and17:49:39
-
Vinayak Pingale over 10 yearsDont convert the string. get the time by using getTime().
-
Justin over 10 yearsSee docs.oracle.com/javase/7/docs/api/java/lang/String.html . Take a close look at substring and indexOf
-
Baby over 10 yearsuse SimpleDateFormat
-