Created
August 3, 2016 11:54
-
-
Save pruinis/c5e85a98df7a9d3b0469e9f21174334a to your computer and use it in GitHub Desktop.
NSDate extension
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// NSDate+Helper.swift | |
// | |
// Created by Anton Morozov on 27.07.16. | |
// Copyright © 2016 Anton Morozov. All rights reserved. | |
// | |
import Foundation | |
extension NSDate { | |
class func minutesPastFromMidnight() -> Int { | |
let gregorian = NSCalendar(identifier: NSCalendarIdentifierGregorian) | |
let unitFlags: NSCalendarUnit = [.Hour , .Minute] | |
let components = gregorian!.components(unitFlags, fromDate: NSDate()) | |
let minutesPastMidnight = 60 * components.hour + components.minute | |
return minutesPastMidnight | |
} | |
func trimTime() -> NSDate { | |
let cal = NSCalendar(calendarIdentifier: NSCalendarIdentifierGregorian)! | |
let components = cal.components([.Day, .Month, .Year], fromDate: self) | |
return cal.dateFromComponents(components)! | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
NSDate
Minutes past from midnight
Removing time components from an NSDate