IHUtil.swift 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. //
  2. // IHUtil.swift
  3. // Inhealth
  4. //
  5. // Created by weclouds on 2019/12/11.
  6. // Copyright © 2019 weclouds. All rights reserved.
  7. //
  8. import UIKit
  9. enum Period {
  10. case normal
  11. case morning
  12. case afternoon
  13. case evening
  14. }
  15. class IHUtil: NSObject {
  16. static let share = IHUtil()
  17. //获取当前时间点
  18. func currentPeriod() -> Period {
  19. let dateformatter = DateFormatter()
  20. dateformatter.dateFormat = "HH"// 自定义时间格式
  21. // GMT时间 转字符串,直接是系统当前时间
  22. let timeStr = dateformatter.string(from: Date())
  23. let hour = Int(timeStr)
  24. if let aHour = hour {
  25. if aHour > 4 && aHour <= 10 {
  26. return .morning
  27. }else if aHour > 10 && aHour <= 18 {
  28. return .afternoon
  29. }else if aHour > 18 && aHour <= 24 {
  30. return .evening
  31. }else{
  32. return .normal
  33. }
  34. }else{
  35. return .normal
  36. }
  37. }
  38. }