如何获取当前时间作为 字符串 (而不是日期)
日期时间格式。
yyyy-MM-dd HH:mm:ss
我就是这样想的。
// Get today date as String func getTodayString() -> String{ let date = Date() let calender = Calendar.current let components = calender.dateComponents([.year,.month,.day,.hour,.minute,.second], from: date) let year = components.year let month = components.month let day = components.day let hour = components.hour let minute = components.minute let second = components.second let today_string = String(year!) + "-" + String(month!) + "-" + String(day!) + " " + String(hour!) + ":" + String(minute!) + ":" + String(second!) return today_string } let today : String! today = getTodayString()