NSDateFormatter Locale

前端 未结 4 1940
Happy的楠姐
Happy的楠姐 2021-01-05 15:19

How to set Locale for NSDateFormatter? I\'ve tried the below code and its not working.

- (NSString *)localizedStringWithFormat:(NSString *)format {

    NSDa         


        
4条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-05 15:42

    A bit late to the party, but this is what I did in Swift today:

    let df = NSDateFormatter()
    df.locale = NSLocale.currentLocale()
    df.timeStyle = .MediumStyle
    df.dateStyle = .MediumStyle
    println("Date: \(df.stringFromDate(obj.dateSent!))")
    

    Depending on your OS region settings, the output should look like this (I'm in Germany):

    Date: 27.11.2014 12:30:39
    

    Note: Just figured a lot more people stumble across this SO question, so I guess it can't hurt to answer.

提交回复
热议问题