// The user’s current calendar. 日历默认为系统当前let cal =Calendar.current
// 日历的 locale 为 nil 或者 Locale.current
cal.locale ==nil// 日历的 timeZone 为 TimeZone.current (The time zone currently used by the system)
cal.timeZone ==TimeZone.current
Demand List 需求列表
已知Date类型的日期对象, 求对应的Int类型的年, 月, 日, 小时, 分钟
var date = xxx;var year = calendar.component(.year, from: date)var month = calendar.component(.month, from: date);var day = calendar.component(.day, from: date);var hour = calendar.component(.hour, from: date);var minute = calendar.component(.minute, from: date);
// Date类型的日期对象let current = xxx
let hour =Calendar.current.component(.hour, from: current)let minute =Calendar.current.component(.minute, from: current)let ms = hour *60+ minute
guard ms <60*18else{return"[18:00~24:00)"}guard ms <12*60else{return"[12:00~18:00)"}guard ms <600else{return"[10:00~12:00)"}guard ms <300else{return"[05:00~10:00)"}return"[00:00~05:00)"
默认环境// The user’s current calendar. 日历默认为系统当前let cal = Calendar.current// 日历的 locale 为 nil 或者 Locale.currentcal.locale == nil// 日历的 timeZone 为 TimeZone.current (The time zone currently used by the system)cal.timeZone == TimeZone.currentDemand List