It was interesting. The main results are:
1 2 3 |
let date = Date() let units: Set<Calendar.Component> = [.hour, .day, .month, .year] let comps = Calendar.current.dateComponents(units, from: date) |
or
1 2 |
let date = Date() let hour = Calendar.current.component(.hour, from: date) |
from https://stackoverflow.com/questions/38248941/how-to-get-time-hour-minute-second-in-swift-3-using-nsdate
and i desided to store date in CoreData as Transformable type.
But I also can do it as String usung something like:
1 2 3 4 5 |
let date = Date() let dateFormater = DateFormatter() dateFormater.dateFormat = "dd-MM-yyyy" let stringDate = dateFormater.string(from: date) expense.date = stringDate |
Well bouth variants work.