Skip to content

Instantly share code, notes, and snippets.

@SatoTakeshiX
Created December 18, 2018 07:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SatoTakeshiX/d3ea2aa2135e46efb4c1906de2b134b4 to your computer and use it in GitHub Desktop.
Save SatoTakeshiX/d3ea2aa2135e46efb4c1906de2b134b4 to your computer and use it in GitHub Desktop.
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
// グレゴリオ暦 = 西暦
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