我正在使用以下代碼獲取當前日期並對其進行格式設置。 但看到錯誤「無法調用initiliazer類型‘日期’不帶參數的」無法在Swift 3.0中獲取當前日期
let currentDateTime = Date()
// initialize the date formatter and set the style
let formatter = DateFormatter()
formatter.timeStyle = .medium
formatter.dateStyle = .long
// get the date time String from the date object
formatter.string(from: currentDateTime) // October 8, 2016 at 10:48:53 PM
截圖
在哪裏這是代碼嗎? – rmaddy
您的項目可能已經定義了另一個名爲「Date」的類?這是從Swift 2遷移的代碼的常見問題,因爲當時Apple的版本被稱爲「NSDate」。 –
從ViewDidLoad()調用getCurrentDate() – Badrinath