gpt4 book ai didi

iphone - 如何使用 NSDateFormatter 查看 "Today"字符串

转载 作者:IT王子 更新时间:2023-10-29 08:02:53 26 4
gpt4 key购买 nike

苹果在今天消息的消息应用中使用它今天上午 11:45昨天上午 11:45

我在苹果开发者网站上看到了

To specify a custom fixed format for a date formatter, you use setDateFormat:. The format string uses the format patterns from the Unicode Technical Standard #35. The version of the standard varies with release of the operating system:

Calendar Fields

fields ( alias | (field*, special*)) > field ( alias | (displayName?, relative*, special*)) >

Translations may be supplied for names of calendar fields (elements of a calendar, such as Day, Month, Year, Hour, and so on), and for relative values for those fields (for example, the day with relative value -1 is "Yesterday"). Where there is not a convenient, customary word or phrase in a particular language for a relative value, it should be omitted.

如何在 Xcode 中使用它?

最佳答案

使用– setDoesRelativeDateFormatting:

NSDateFormatter *dateFormatter = [NSDateFormatter new];

dateFormatter.dateStyle = NSDateFormatterShortStyle;
dateFormatter.timeStyle = NSDateFormatterShortStyle;

dateFormatter.doesRelativeDateFormatting = YES;

NSLog(@"%@", [dateFormatter stringFromDate:[NSDate date]]);

这会在 en_US 语言环境中记录今天上午 11:30

关于iphone - 如何使用 NSDateFormatter 查看 "Today"字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18682206/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com