All,
I have a date format "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"
and I need to set the millisecond value, but date component does not provide millisecond attribute.
Below is my code for setting custom values in hour, minute, second. I also need to set millisecond to 0/999
value.
static func getToadyStartInUTC() -> String{
let todaydate = Date()
let formatter = DateFormatter()
var components = Calendar.current.dateComponents([.year, .month, .day, .hour], from: todaydate)
components.hour = 0
components.minute = 0
components.second = 0
let calendar = Calendar.current
let startDate = calendar.date(from: components)!
print("\(startDate)")
formatter.timeZone = TimeZone(identifier: "UTC")
formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"
return formatter.string(from: startDate)
}
How can I set the millisecond value in date component?