字符串转变格式:
func getNotifacationCellTime(str: String) -> String {
lettimeFormatter =DateFormatter()
timeFormatter.dateFormat="yyyyMMddHHmmss+HHmm"
///传入字符串要和dateFormat 格式保持一致
lettimeDate = timeFormatter.date(from: str)
timeFormatter.dateFormat="yyyy/MM/dd HH:mm"
letcurrentTime = timeFormatter.string(from: timeDate!asDate)asString
returncurrentTime
}
获取当前时间:
/// 注意日期格式的大小写
func getTimesstamp() -> String {
letdate =NSDate()
lettimeFormatter =DateFormatter()
timeFormatter.dateFormat="yyyyMMddHHmmssZ"
timeFormatter.timeZone=NSTimeZone(name:"UTC+9")asTimeZone?
letcurrentTime = timeFormatter.string(from: dateasDate)asString
returncurrentTime
}
网友评论