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.


Popular posts from this blog

Php - Delimiter must not be alphanumeric or backslash -

c# - How to change the "Applies To" field under folder auditing options programatically (.NET) -

c++ - Ambiguity when using boost::assign::list_of to construct a std::vector -