我試圖將圖像上傳到服務器如何獲得實際的時間和日期swift3
我的網址 - https://www.zdoof.com/api/zTimeline/insert_post
我的參數是 -
"Is_checkin" : "0",
"Description" : self.cookingText.text!,
"Videolink" : "",
"Post_image" : imageStr,
"Created_by" : "4490",
"Created_on" : "10/Oct/2017"
The parameter(Created_on) taking the date & time format like (dd/MMM/yyyy HH:mm:ss).
當我只給出像(10/10/2017)這樣的日期格式,上傳就是成功。但默認情況下需要花費時間,如12:00:00。
但我想給實際的時間作爲參數。如何編碼日期和時間格式,以便它會給出實際時間。
的日期和時間,我的代碼 -
let dateFormatter : DateFormatter = DateFormatter()
dateFormatter.dateFormat = "dd/MMM/yyyy"
let date = Date()
let myString = dateFormatter.string(from: date)
let data = myString.data(using: .utf8)
self.dateString = String(data: data!, encoding: .utf8)!
)
let timeFormatter : DateFormatter = DateFormatter()
timeFormatter.dateFormat = "HH:mm:ss"
let calendar = NSCalendar.current
let hour = calendar.component(.hour,from: NSDate() as Date)
let minute = calendar.component(.minute,from: NSDate() as Date)
let second = calendar.component(.second,from: NSDate() as Date)
let hourString = String.init(describing: hour)
let minuteString = String.init(describing: minute)
let secondString = String.init(describing: second)
self.timeString = hourString + ":" + minuteString + ":" + secondString
請幫我把日期和時間轉換爲實際日期和時間