📌  相关文章
📜  从可用字符串中快速获取日期 - Swift 代码示例

📅  最后修改于: 2022-03-11 15:00:58.928000             🧑  作者: Mango

代码示例1
let dateString = "2018-12-24 18:00:00 UTC"
    let formatter = DateFormatter()
    formatter.dateFormat = "yyyy-MM-dd HH:mm:ss 'UTC'"
    guard let date = formatter.date(from: dateString) else {
        return
    }

    formatter.dateFormat = "yyyy"
    let year = formatter.string(from: date)
    formatter.dateFormat = "MM"
    let month = formatter.string(from: date)
    formatter.dateFormat = "dd"
    let day = formatter.string(from: date)
    print(year, month, day) // 2018 12 24