iphone Get current year as string

后端 未结 5 1185
迷失自我
迷失自我 2021-02-01 01:33

How do I get current year as string in Obj-C ?

Also how do I compare the same using another year value ?

Is it advisable to do a string comparision OR dirctly ye

5条回答
  •  余生分开走
    2021-02-01 02:37

    In Swift you can get only year by given code

    let formatter = NSDateFormatter()
    formatter.dateFormat = "yyyy"
    let dateStr = formatter.stringFromDate(NSDate())
    print(dateStr)
    

    Output:

    2017

提交回复
热议问题