Created
July 3, 2020 08:56
-
-
Save xiangyu-sun/e57c5162f2406b512f5a53131cdd5967 to your computer and use it in GitHub Desktop.
Using apple's formatter to get Chinese yang calendar detail
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 calendar = Calendar(identifier: .chinese) | |
let formatter = DateFormatter() | |
formatter.calendar = calendar | |
formatter.dateStyle = .long | |
let regex = try? NSRegularExpression(pattern: ##"(\w*)-(\w*)"##) | |
let str = formatter.string(from: self) | |
let matches = regex?.matches(in: str, options: [], range: NSRange(location: 0, length: str.count)) | |
var dizhi: String? | |
matches?.forEach { (result) in | |
let ns = (str as NSString) | |
dizhi = ns.substring(with: result.range(at: 2)) | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment