【问题标题】:How can I use NSDateFormatter to get the string "Yesterday"? [closed]如何使用 NSDateFormatter 获取字符串“昨天”? [关闭]
【发布时间】:2013-01-10 03:09:07
【问题描述】:

我想格式化我的NSDate,以便昨天发生的日期将显示为“昨天”。这可以使用NSDateFormatter 完成吗?

【问题讨论】:

  • 这完全是一个真实的问题,有一个真实的答案,Breakpoint 已经提供了。
  • 这个问题不应该被关闭。

标签: ios nsdate nsdateformatter


【解决方案1】:

使用,

[dateFormatter setDoesRelativeDateFormatting:YES]

指示是否需要在短语中打印日期组件的输出,如“今天”、“明天”等。 但是,输出短语取决于为 dateFormatter 设置的 locale

阅读NSDateFormatter Class Reference 的管理自然语言支持以了解更多详情。

【讨论】:

    猜你喜欢
    • 2015-10-05
    • 1970-01-01
    • 2020-12-31
    • 2014-09-07
    • 1970-01-01
    • 1970-01-01
    • 2013-05-06
    • 1970-01-01
    • 2013-09-11
    相关资源
    最近更新 更多