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

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -