If we have array of dates and we need to find what date is neasrest to today date. There is special method in iOS SDK API - timeIntervalSince
This method will return double value - time interval between two dates - self date object and parameter date. Also this time interval can be positive or negative. So for getting nearest date we need to get absolute positive value of time interval. For that purpose we will use method fabs
Algorithm - How to define nearest date to today
Search This Blog
Showing posts with label Date. Show all posts
Showing posts with label Date. Show all posts
Wednesday, November 23, 2016
Monday, October 10, 2016
iOS Swift. How to show Date in local Time Zone
For showing date in local time zone we need to use DateFormatter class and set to it our local time zone:
let date = Date() let dateFormatter = DateFormatter() dateFormatter.dateFormat = "dd.MM.yyyy HH:mm" let localTZ = TimeZone.current dateFormatter.timeZone = localTZ print(localTZ.abbreviation()) self.userLastTimeRefreshedLabel.text = String("\(dateFormatter.string(from: date))")
Subscribe to:
Posts (Atom)