Skip to content

Instantly share code, notes, and snippets.

@s2339956
Created October 5, 2017 03:43
Show Gist options
  • Save s2339956/5f70990a4545bb00ee401de70dfeb549 to your computer and use it in GitHub Desktop.
Save s2339956/5f70990a4545bb00ee401de70dfeb549 to your computer and use it in GitHub Desktop.
// swift 3
// 取得時間 西元年 轉 -> 民國年
let nowDate = Date()
let dateFormatter = DateFormatter()
dateFormatter.dateStyle = .short
dateFormatter.timeStyle = .medium
dateFormatter.dateFormat = "yyy/MM/dd HH:mm"
let chineseCal = NSCalendar(calendarIdentifier: NSCalendar.Identifier.republicOfChina)
dateFormatter.calendar = chineseCal! as Calendar
let dataString = dateFormatter.string(from: nowDate)
print(dataString)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment