NSDateformatter setDateFormat according to currentLocale

前端 未结 6 2145
孤城傲影
孤城傲影 2021-02-14 12:17

I\'m going mad with, probably, a stupid problem.

I have 3 strings: year, month and day. I need to have a date in the right format based on currentLocale, so i.e. if curr

6条回答
  •  一生所求
    2021-02-14 12:44

    In Swift 3:

    let formatter = DateFormatter()
    formatter.dateStyle = .medium
    formatter.timeStyle = .none
    formatter.locale = Locale.current
    let date = Date()
    let dateString = formatter.string(from: date)
    print(dateString)
    

提交回复
热议问题