问题
I want to format my NSDate
so that a date that occurred yesterday will be displayed as "Yesterday'. Can this be done using NSDateFormatter
?
回答1:
Use,
[dateFormatter setDoesRelativeDateFormatting:YES]
to indicate if an output of date components need to be printed in a phrase or not, as "Today", "Tomorrow" etc.
The output phrases however, depend on the locale
set for the dateFormatter
Read through the Managing Natural Language Support of the NSDateFormatter Class Reference for further details.
来源:https://stackoverflow.com/questions/14250235/how-can-i-use-nsdateformatter-to-get-the-string-yesterday