String description of NSDate

前端 未结 4 1976
星月不相逢
星月不相逢 2021-01-31 10:30

I have the following code:

[ [NSDate date] descriptionWithLocale: @\"yyyy-MM-dd\" ]

I want it to return a date in the following format: \"2009-

4条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-31 11:26

    If you don't have NSDate -descriptionWithCalendarFormat:timeZone:locale: available (I don't believe iPhone/Cocoa Touch includes this) you may need to use strftime and monkey around with some C-style strings. You can get the UNIX timestamp from an NSDate using NSDate -timeIntervalSince1970.

提交回复
热议问题