Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Difference between @"MM/dd/yyyy" and @"MM/dd/YYYY" in setDateFormat.

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 546
    Comment on it

    The difference may seem very small but it makes a lot of changes in the ways things work.The year when written in small letters (setDateFormat:@"MM/dd/yyyy") is the ordinary calendar and will return normal year, but in case of the capital YYYY, (setDateFormat:@"MM/dd/YYYY") the date formatter will use the week-based calendar.

    The week-based calendar use weeks as a reference for the year as opposed to dates of the month. It works fine most of the time but will cause problems in the last dates of December and the First week dates of January.

    so if for example the date is 2-Jan-2014, which is thursday. The Week-based date formatter is going to return 2-Jan-2013 because the week is the last week of 2013 i.e. the week started in 2013, so the year will be 2013. This may cause problems in most unexpected places.

    //for normal calendar.
    
    [dateFormatter setDateFormat:@"MM/dd/yyyy"];
    
    //for week-based calendar
    
    [dateFormatter setDateFormat:@"MM/dd/YYYY"];
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: