Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

dd/mm/yyyy vs dd/MM/yyyy?

SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");         String date = sdf.format(new Date());          System.out.println(date);  

Result is todays date i.e 23/03/2014

But when i do

 SimpleDateFormat sdf = new SimpleDateFormat("dd/mm/yyyy");  

result can be 23/05/2014, 23/05/2014, 23/06/2014 and son with each run of prgram. Why so?

like image 949
user3198603 Avatar asked Mar 23 '14 11:03

user3198603


People also ask

Is mm/dd/yyyy format correct?

The ISO 8601 format YYYY-MM-DD (2022-08-30) is intended to harmonize these formats and ensure accuracy in all situations. Many countries have adopted it as their sole official date format, though even in these areas writers may adopt abbreviated formats that are no longer recommended.

Is mm/dd/yyyy American?

Despite the variety of date formats used around world, the US is the only country to insist on using mm-dd-yyyy.

What is difference between MM and MM in date format?

mm represents minutes, so when you use mm , it will print minutes instead of month. While MM represents months.


2 Answers

It's because mm is for minutes, not months. More in the documentation.

like image 114
T.J. Crowder Avatar answered Sep 22 '22 16:09

T.J. Crowder


In C# and VB.NET, it's a case sensitive especially to format the Month or Minutes. Because initial character of both the words is same.

The following detail may help you in formatting the date & time.

1. d/D: day without 0 prefix on single digit.  2. dd/DD: day with 0 prefix if single digit. 3. M: Month without 0 prefix on single digit. 4. MM: Month with 0 prefix if single digit. 5. yy/YY: Last two digit of year. 6. yyyy/YYYY: represents full year. 7. HH: 24 hour based hour. ie. 13:00. **H** will display hour without prefix 0 if single digit 8. hh: 12 hour based hour. ie. 01:00. **h** will display hour without prefix 0 if single digit 9. m: minute without 0 prefix on single digit.  10.mm: minute with 0 prefix if single digit. 11.s: second without 0 prefix on single digit.  12.ss: second with 0 prefix if single digit. 13.tt: represent the AM or PM 
like image 41
Shell Avatar answered Sep 20 '22 16:09

Shell