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

Popular posts from this blog

qt - switch/case statement in C++ with a QString type -

python - sqlite3.OperationalError: near "REFERENCES": syntax error - foreign key creating -

Python's equivalent for Ruby's define_method? -