Q:

How to get Date, Month and Year into Millisecond in swift

Hi am Trying to convert year, month date into Millisecond how to do please help me to do this,
Bellow Is my Code that i have try.
let date:String = "2018-08-04T07:34:15.287Z"
let dateFormatter = DateFormatter()
dateFormatter.timeZone = TimeZone.current
dateFormatter.dateFormat = "yyyy-MM-dd"

var dateFromString = Date()
if let aString = dateFormatter.date(from: date) {
    dateFromString = aString
}

let timeInMiliseconds:Int = Int(TimeInterval(dateFromString.timeIntervalSince1970 * 1000))

return timeInMiliseconds

But I Alway Got DateTime Into Millisecond.
when I am trying to get the only date into millisecond please help I need help.
Thanks in advance.

A:

Your dateFormat is not match with date. Try below code:
let date:String = "2018-08-04T07:34:15.287Z"
let dateFormatter = DateFormatter()
dateFormatter.timeZone = TimeZone.current
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZ"

dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZ"
let dateToConvert = dateFormatter.date(from: date)

dateFormatter.dateFormat = "yyyy-MM-dd"
let finalDate = dateFormatter.string(from: dateToConvert!)

var dateFromString = Date()
if let aString = dateFormatter.date(from: finalDate) {
    dateFromString = aString
}

let timeInMiliseconds:Int = Int(TimeInterval(dateFromString.timeIntervalSince1970 * 1000))

You will get 1533321000000 in timeInMiliseconds

You can check time here

