How do I format the current date for the user's locale?

后端 未结 4 734
难免孤独
难免孤独 2021-02-05 09:00

I have this code where I\'m trying to get the current date and format it in the current locale.

NSDate *now = [NSDate date];  //  gets current date
NSString *sNo         


        
4条回答
  •  星月不相逢
    2021-02-05 09:17

    If you want the localized date and time this will give it to you:

        NSString *localizedDateTime = [NSDateFormatter localizedStringFromDate:[NSDate date] dateStyle:NSDateFormatterShortStyle timeStyle:NSDateFormatterShortStyle];
    

    The code above does not give you the localized date and time.

提交回复
热议问题