I am having trouble displaying the date in a double digit format. I want it to be so that when the day or the month is a single digit example: 4 It would display 04. I'm having trouble coming up with the logic for it, if somebody can help me I would be really grateful.
Calendar c = Calendar.getInstance(); int year = c.get(Calendar.YEAR); int day = c.get(Calendar.DAY_OF_MONTH); int month = c.get(Calendar.MONTH); if (month % 10 == 0) { Place = 0 + month; } String Dates = year + "-" + Place + "-" + day; Date.setText((Dates));
Use the getMonth() method to get the month for the given date. Use the getDate() method to get the day of the month for the given date. Use the padStart() method to get the values in a 2-digit format.
dd/MM/yyyy — Example: 23/06/2013. yyyy/M/d — Example: 2013/6/23. yyyy-MM-dd — Example: 2013-06-23. yyyyMMddTHH:mmzzz — Example: 20130623T13:22-0500.
According to wikipedia, the only countries that use the MM/DD/YYYY system are the US, the Philippines, Palau, Canada, and Micronesia. I would presume these other countries, being close to or influenced by the US, have picked it up from the US, indicating that it is a US creation.
DecimalFormat mFormat= new DecimalFormat("00"); mFormat.format(Double.valueOf(year));
in your case:
mFormat.setRoundingMode(RoundingMode.DOWN); String Dates = mFormat.format(Double.valueOf(year)) + "-" + mFormat.format(Double.valueOf(Place)) + "-" + mFormat.format(Double.valueOf(day));
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