swift 4 – 國曆轉農曆

let dateAt: String = “2016/1/1”
let dateFormatter: DateFormatter = DateFormatter()
dateFormatter.dateFormat = “yyyy/MM/dd”
let dateComps: NSDateComponents = NSCalendar(calendarIdentifier: NSCalendar.Identifier.chinese)!.components([.year, .month, .day], from: dateFormatter.date(from: dateAt)!) as NSDateComponents
print(“\(dateAt) => Chinese calendar date (Lunar): \(dateComps.month)/\(dateComps.day)”)

之前的 swift – 國曆轉農曆 已經不能用了

Leave a Reply

Your email address will not be published. Required fields are marked *


This site uses Akismet to reduce spam. Learn how your comment data is processed.