Swift 3 获取当前日期是第几周

Swift 3 获取当前日期是第几周
func GetWeekByDate(date:Date) ->String{
        guard let calendar = NSCalendar(identifier: NSCalendar.Identifier.gregorian) else {
            return ""
        }
        let components = calendar.components([.weekOfYear,.weekOfMonth,.weekday,.weekdayOrdinal], from: date)
        //今年的第几周
        let weekOfYear = components.weekOfYear!
        
        //这个月第几周
        let weekOfMonth = components.weekOfMonth!
        //周几
        let weekday = components.weekday!
        //这个月第几周
        let weekdayOrdinal = components.weekdayOrdinal!
        print(weekOfYear)
        print(weekOfMonth)
        print(weekday)
        print(weekdayOrdinal)
        return "第\(components.weekOfYear!)周";
    }
  • 发表于 2017-11-24 09:34
  • 阅读 ( 671 )
  • 分类:ios

相关问题

0 条评论

请先 登录 后评论
不写代码的码农
Alan

iOS开发

14 篇文章

作家榜 »

  1. 威猛的小站长 108 文章
  2. Jonny 65 文章
  3. 江南烟雨 33 文章
  4. - Nightmare 33 文章
  5. doublechina 31 文章
  6. HJ社区-肖峰 29 文章
  7. 伪摄影 20 文章
  8. Alan 14 文章