Created
December 18, 2018 07:32
-
-
Save SatoTakeshiX/d3ea2aa2135e46efb4c1906de2b134b4 to your computer and use it in GitHub Desktop.
Swiftで旧暦を扱う ref: https://qiita.com/SatoTakeshiX/items/f58ed3fb9d8beb16273b
This file contains 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 today = Date() //2018年12月18日に実行 | |
// 中国の農暦 = 旧暦 | |
let chineseCalendar = Calendar(identifier: .chinese) | |
let comp = chineseCalendar.dateComponents([.year, .month, .day], from: today) | |
print(comp.debugDescription) | |
// year: 35 month: 11 day: 12 isLeapMonth: false |
This file contains 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 gregrianCalendar = Calendar(identifier: .gregorian) | |
var compornents = DateComponents() | |
compornents.year = 2018 | |
compornents.month = 12 | |
compornents.day = 18 | |
// 西暦からDate型を作る | |
let gregrianDate = gregrianCalendar.date(from: compornents)! | |
// 中国の農暦 = 旧暦 | |
let chineseCalendar = Calendar(identifier: .chinese) | |
// 旧暦に変換 | |
let chineseComps = chineseCalendar.dateComponents([.year, .month, .day], from: gregrianDate) | |
print(chineseComps.debugDescription) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment