IOS-Swift 获取当前日期 星期

  • Post author:
  • Post category:其他





//


获取当前日期




let


moonDay =


Date


().


stringWithFormatterL


(dateFormat:


“M





dd








)




let


time =


Date


().


stringWithFormatterL


(dateFormat:


“HH:mm”


)




let


weekDay =


Date


().


weekDay


()




DLog


(





\


(


moonDay


)——


\


(


time


)——


\


(


weekDay


)”


)




//


获取星期几




func


weekDay() ->


String


{





let


weekDays = [


NSNull


.


init


(),





周日





,





周一





,





周二





,





周三





,





周四





,





周五





,





周六





]


as


[


Any


]





let


calendar =


NSCalendar


.


init


(calendarIdentifier: .


gregorian


)




let


timeZone =


NSTimeZone


.


init


(name:


“Asia/Shanghai”


)


calendar?.


timeZone


= timeZone


as


!


TimeZone





let


calendarUnit =


NSCalendar


.


Unit


.


weekday





let


theComponents = calendar?.


components


(calendarUnit, from:


self


)






return


weekDays[(theComponents?.


weekday


)!]


as


!


String



}



版权声明:本文为onlychengzhi原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。