Created
September 10, 2018 21:38
-
-
Save erdemarslan/22b2f137613be1ba7d60d606f572818a to your computer and use it in GitHub Desktop.
Date ile ilgili kullanışlı extensionlarım
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
| extension Date { | |
| func hour() -> Int { | |
| //Get Hour | |
| let calendar = Calendar.current | |
| let components = calendar.component(.hour, from: self as Date) | |
| let hour = components.hashValue | |
| //Return Hour | |
| return hour | |
| } | |
| func minute() -> Int { | |
| //Get Minute | |
| let calendar = Calendar.current | |
| let components = calendar.component(.minute, from: self as Date) | |
| let minute = components.hashValue | |
| //Return Minute | |
| return minute | |
| } | |
| func toShortTimeString() -> String { | |
| //Get Short Time String | |
| let formatter = DateFormatter() | |
| formatter.timeStyle = .short | |
| formatter.dateFormat = "HH:mm" | |
| let timeString = formatter.string(from: self as Date) | |
| //Return Short Time String | |
| return timeString | |
| } | |
| func toShortDateString() -> String { | |
| let formatter = DateFormatter() | |
| formatter.dateFormat = "YYYY/MM/dd" | |
| let dateString = formatter.string(from: self as Date) | |
| return dateString | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment