Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove the SECONDS field from a DateFormat

I want to print a time without seconds in the default format for the locale. So I get the formatter with getTimeInstance() or getTimeInstance(int style). But even when I use a SHORT style it will contain the seconds part of the time as well.

Is there any way (apart from creating my own format, which then would not be the locale default and manually maintained) I can grab the default and split off the seconds ?

Thanks

Roman

like image 438
roetzi Avatar asked Nov 30 '22 12:11

roetzi


2 Answers

EDIT: This is insufficient (as stated by the first comment below). I'm keeping this here for the sake of history and to keep others from responding in a similar fashion :)


Have you considered saving the current format as a string and manually removing the seconds using String's substring method?

like image 44
loeschg Avatar answered Dec 04 '22 02:12

loeschg


DateFormat.getTimeInstance(DateFormat.SHORT) works perfectly fine here: from 20:00:00 to 20:00 and from 8:00:00 PM to 8:00 PM.

like image 177
Guillaume Avatar answered Dec 04 '22 04:12

Guillaume