Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Displaying date in a double digit format

Tags:

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)); 
like image 988
The Tokenizer Avatar asked Apr 18 '12 06:04

The Tokenizer


People also ask

How do I get month and date of JavaScript in 2 digit format?

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.

How do you format mm dd yyyy?

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.

Which countries use YYYY-MM-DD format?

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.


1 Answers

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)); 
like image 130
Mohammed Azharuddin Shaikh Avatar answered Sep 23 '22 01:09

Mohammed Azharuddin Shaikh