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
| func normalDate(fromYear year: Int, month: Int, day: Int) -> Date { | |
| var normalCalendarDateComponents = DateComponents() | |
| normalCalendarDateComponents.year = year | |
| normalCalendarDateComponents.month = month | |
| normalCalendarDateComponents.day = day | |
| let normalCalendar = Calendar(identifier: .gregorian) | |
| let normalDate = normalCalendar.date(from: normalCalendarDateComponents)! | |
| return normalDate | |
| } |
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
| guard let hyphen = chineseDate.firstIndex(of: "-") else { | |
| fatalError("\(chineseDate) is not correctly formatted, use DateFormatter.Style.full") | |
| } | |
| let startIndex = chineseDate.index(after: hyphen) | |
| let endIndex = chineseDate.index(chineseDate.endIndex, offsetBy: -2) | |
| let branch = chineseDate[startIndex ... endIndex] | |
| print(branch) |
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
| let dict = [ | |
| "zi": "rat", | |
| "chou": "ox", | |
| "yin": "tiger", | |
| "mao": "rabbit", | |
| "chen": "dragon", | |
| "si": "snake", | |
| "wu": "horse", | |
| "wei": "goat", | |
| "shen": "monkey", |
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
| let formatter = DateFormatter() | |
| formatter.dateFormat = "MMM d, yyyy" | |
| formatter.calendar = .init(identifier: .chinese) | |
| formatter.dateStyle = .full | |
| print(formatter.string(from: normalDate)) |
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
| let formatter = DateFormatter() | |
| formatter.dateFormat = "MMM d, yyyy" | |
| print(formatter.string(from: normalDate)) |
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
| let calendar = Calendar(identifier: .gregorian) | |
| let normalDate = calendar.date(from: normalCalendarDateComponents)! |
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
| What Swift gives us | What it says in Chinese | Associated Zodiac | |
|---|---|---|---|
| zi | 子 | rat | |
| chou | 丑 | ox | |
| yin | 寅 | tiger | |
| mao | 卯 | rabbit | |
| chen | 辰 | dragon | |
| si | 巳 | snake | |
| wu | 午 | horse | |
| wei | 未 | goat | |
| shen | 申 | monkey |
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
| var normalCalendarDateComponents = DateComponents() | |
| normalCalendarDateComponents.year = 2020 | |
| normalCalendarDateComponents.month = 5 | |
| normalCalendarDateComponents.day = 1 |
NewerOlder