CocoaPods trunk is moving to be read-only. Read more on the blog, there are 13 months to go.
| TestsTested | ✗ |
| LangLanguage | SwiftSwift |
| License | MIT |
| ReleasedLast Release | Sep 2016 |
| SPMSupports SPM | ✗ |
Maintained by ltebean.
pod 'LTSwiftDate'
NSDate to String
let time = NSDate().toString(format: "MM/dd/yyyy") // 04/08/2016
let time = NSDate().toString(format: "MMM d, H:mm a") // Apr 8, 8:29 AMString to NSDate
"04/08/2016".toDate(format: "MM/dd/yyyy")You can find the complete reference for the format string here: http://nsdateformatter.com/
LTSwiftDate adds exension on Int to generate date components, it supports:
secondsminuteshoursdaysweeksyearsExample:
let now = NSDate()
let nextMinute = now + 1.minutes
let yesterday = now - 1.days
let lastMonth = now - 1.months
...You can compare dates using:
>>===<<=Example:
let now = NSDate()
let tomorror = now + 1.days
if (now < tomorrow) {
...
}
now.isEqualToDate(now + 1.mins, ignoreTime=true) // truelet now = NSDate()
let startOfDay = now.startOfDay()
let endOfDay = now.endOfDay()
let now = NSDate()
let tomorrow = now + 1.days
let days = now.daysBeforeDate(tomorrow) // days will be 1