I know a lot of tutorials there about calendar giving minute and hours without leading zero. But those doesnt work for my codes. Can someone help me how to do this base on my codes? Calendar.MINUTE is not showing the zero integer whenever the minite is from 0-9.
Calendar cal = GregorianCalendar.getInstance();
String am_pm, hour;
cal.add(Calendar.MONTH, +1);
if(cal.get(Calendar.AM_PM) == 0)
am_pm = "AM";
else
am_pm = "PM";
tv.setText(cal.get(Calendar.MONTH) + "-" + cal.get(Calendar.DAY_OF_MONTH) + "-" + cal.get(Calendar.YEAR));
tv2.setText(cal.get(Calendar.HOUR) + ":" + cal.get(Calendar.MINUTE) + " " + am_pm);
tv3.setText("Offered");
you can use DateFormat or Simple way to do this is
String month=String.format("%02d",cal.get(Calendar.MONTH));
String day=String.format("%02d",cal.get(Calendar.DAY_OF_MONTH));
String year=String.format("%02d",cal.get(Calendar.YEAR));
tv.setText( month+ "-" + day + "-" +year );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With