How to change date format for date picker view?

Discussion in 'iOS Programming' started by mikezang, Oct 16, 2010.

  1. mikezang macrumors 6502a

    Joined:
    May 22, 2010
    Location:
    Tokyo, Japan
    #1
    I tested Apple's DateCell sample, it shows as left below, then I modified code so it shows like at right.
    I want to let Date Picker View also shows in "yyyy/MM/dd" format, what can I do?
    Code:
    - (void)viewDidLoad
    {
        self.dataArray = [NSArray arrayWithObjects:@"Start Date", @"End Date", nil];
    	
        self.dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
        [self.dateFormatter setDateStyle:NSDateFormatterShortStyle];
        [self.dateFormatter setTimeStyle:NSDateFormatterNoStyle];
        [self.dateFormatter setDateFormat:@"yyyy/MM/dd"];
    }
     

    Attached Files:

  2. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    I believe the picker uses the correct format for the locale set on the phone. For example my phone is set to UK locale and I get day-month-year in date pickers. To the best of my knowledge you cannot change this: the user expects the picker behaviour to be consistent.
     
  3. mikezang thread starter macrumors 6502a

    Joined:
    May 22, 2010
    Location:
    Tokyo, Japan
    #3
    I am in Japan, do you know why it doesn't show in Japanese format with 'yyyy/MM/dd', but in US format with 'mmm dd yyyy'?
     
  4. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #4
    What is your Region Format using in General->International? What does the Calendar app show if you create a new All Day event?
     
  5. mikezang thread starter macrumors 6502a

    Joined:
    May 22, 2010
    Location:
    Tokyo, Japan
    #5
    I am sorry, what General? Xcode or Mac OS X?
     
  6. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #6
    None of the above. Settings->General makes perfect sense on an iOS device so the context should have been clear. If you are running in the Simulator then it also has a Settings app with a General section. On my system even though my Mac is set to UK in Settings->General in the simulator it says United States. I would expect a competent developer to check these things themselves...
     
  7. mikezang thread starter macrumors 6502a

    Joined:
    May 22, 2010
    Location:
    Tokyo, Japan
    #7
    Thank you very much! I got what I need.
     

Share This Page