How do I take a date and extract the day in iOS"

前端 未结 5 1555
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-19 16:15

I have a webservice that returns the date in this format:

2013-04-14

How do i figure out what day this corresponds to?

5条回答
  •  旧巷少年郎
    2020-12-19 17:15

    Swift 3:


    let datFromat = DateFormatter()
    
    datFormat.dateFormat = "EEEE"
    
    let name = datFormat.string(from: Date())
    

    Bonus: If you want to set your own date template instead of using Date() above:

    let datFormat = DateFormatter()
    
    datFormat.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZZZZZ"
    
    let thisDate = datFormat.date(from: "2016-10-13T18:00:00-0400")
    

    Then call the 1st code after this.

提交回复
热议问题