java - convert String in time to Time object without Date -
I have a problem converting string time into a time object because it prints with date, this is my code
string time = "15:30:18"; Date format SDF = new SimpleDateform ("HH: mm: SS"); Date date = sdf Prs (time); System.out.println ("time:" + date); How to convert and print only time without a date in Java. It would be better if you can give an example.
Thank you.
Use the same SimpleDateFormat that you used to parse it: string time = "15: 30" ;; Date format SDF = new SimpleDateform ("HH: mm: SS"); Date date = sdf Prs (time); System.out.println ("Time:" + sdf.format (date)); Remember, the date object always represents a combined date / time value; it can not represent only the date-only or the time-value value That's why you have to use the correct DateFormat to ensure that you "only see" the desired parts.
Comments
Post a Comment