java - Stop date dropping zero's -
how stop ints dropping zeros in time? i've tried formatting
string.format("%02d", minutes);
but doesn't work, i'm sure it's quite simple!
date dt = new date(); int hours = dt.gethours(); int minutes = dt.getminutes(); string curtime = hours + ":" + minutes; string.format("%02d", minutes); updatedat.settext("updated @ " + curtime);
use simpledateformat object instead format dates/times.
date date = new date(); // initializes current time dateformat df = new simpledateformat("h:mm"); updatedat.settext("updated @ " + df.format(date));
read more simpledateformat , formatting specifications here.