我希望将日期格式(22/03/2016 23:59:59)格式化为字符串,以毫秒为单位。
dr.GetDateTime(1).ToString(“yyyy-MM-dd hh:mm:ss”)
let task = URLSession.shared.dataTask(with: request) { (data, uRLResponse, responseError) in
DispatchQueue.main.async {
var httpResponse = uRLResponse as! HTTPURLResponse
if responseError != nil && httpResponse.statusCode == 200{
successHandler(data!)
}else{
if(responseError == nil){
//Trying to achieve something like below 2 lines
//Following line throws an error soo its not possible
//var errorTemp = Error(domain:"", code:httpResponse.statusCode, userInfo:nil)
//failureHandler(errorTemp)
}else{
failureHandler(responseError!)
}
}
}
}
.ToString("yyyy-MM-dd")
答案 0 :(得分:4)
如果您使用Google DateTime.ToString(),则最终会使用MSDN documentation来解释此功能。
然后你可以找到Custom Date and Time Format的链接,它解释了要显示毫秒,你必须这样做:
dr.GetDateTime(1).ToString("yyyy-MM-dd hh:mm:ss fff")