- objective-c - iOS 5 : Can you override UIAppearance customisations in specific classes?
- iphone - 如何将 CGFontRef 转换为 UIFont?
- ios - 以编程方式关闭标记的信息窗口 google maps iOS
- ios - Xcode 5 - 尝试验证存档时出现 "No application records were found"
在 NSDateFormatter 文档中,
If a date formatter uses relative date formatting, where possible it replaces the date component of its output with a phrase—such as “today” or “tomorrow”—that indicates a relative date.
我正在使用以下代码:
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
formatter.dateFormat = [NSDateFormatter dateFormatFromTemplate:@"EEEE dMMMM',' hma"
options:0
locale:[NSLocale currentLocale]];
formatter.doesRelativeDateFormatting = YES;
NSLog(@"Date: %@", [formatter stringFromDate:[NSDate date]]);
它记录日期:
。
但是在注释掉 formatter.doesRelativeDateFormatting = YES;
时输出是正确的。
日期:8 月 19 日星期二下午 1:18
我对 doesRelativeDateFormatting
的理解有误吗?
最佳答案
嗨,当我像这样修改代码时。它有效..
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
formatter.dateFormat = [NSDateFormatter dateFormatFromTemplate:@"EEEE dMMMM',' hma"
options:0
locale:[NSLocale currentLocale]];
[formatter setDateStyle:NSDateFormatterFullStyle];
[formatter setTimeStyle:NSDateFormatterShortStyle];
formatter.doesRelativeDateFormatting = YES;
NSLog(@"Date: %@", [formatter stringFromDate:[NSDate date]]);
关于ios - 在设置 doesRelativeDateFormatting = YES 时,stringFromDate 返回 nil,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25378188/
#define stdDateFormat @"YYYYMMdd'T'hh:mm:ssZ" NSDateFormatter *dateFormat = [[NSDateFormatter alloc]
我使用 NSDateFormatter 将时间戳转换为字符串这是我的代码 let string = NSString(string: timeStamp) let timeSta:NSTimeInte
我做错了什么? 我正在尝试 getNSDateFormatter 使用当前区域设置转换日期的自定义模式。 示例: dateFormat = [[NSDateFormatter alloc] i
简单/基本问题: 如果我不关心格式化所获取的日期,两者之间的性能差异是什么? NSDate *date = [NSDate date]; NSSting *dateString = [NSStri
所以这里有一些我遇到问题的代码: //format the date to a string for echoing it NSDateFormatter* formattedDate = [
所以,我有 let formatter: NSDateFormatter = NSDateFormatter() formatter.dateFormat = "yyyy MM dd" 然后我有 da
我知道这是一个重复的问题,但在 stackoverflow 和 google 上搜索了许多类似的问题后,没有一个解决方案适合我。 我正在尝试将从数据库接收到的日期转换为字符串格式,以便在 iPhone
我有一个字符串格式的日期,格式如下: "2015-11-15 14:16:15 +0000" 我想以本地化格式显示它,甚至计算年龄。要访问 NSDate,我使用以下代码: dateFormatter.
我有一个简单的小测试程序——两个标签和两个按钮。当您点击这两个按钮中的任何一个时,顶部标签会显示相应按钮的 currentTitle 属性。第二个标签应显示点击按钮的时间,但在删除原始“标签”文本后显
我有一些简单的代码可以转换我从 CoreData 检索到的 NSDate。出于某种原因,当相同的代码在其他 View 中工作时,它在此类中不起作用。我究竟做错了什么?下面是有问题的代码和我的日志的屏幕
NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; [formatter setDateFormat:@"hh:mm:ss
我正在尝试使用 NSDateFormatter 将保存的日期更改为山区标准时间,但它似乎不起作用。 正在输出“currentDate: 2013-02-22 23:20:20 +0000 date W
我正在尝试以 dd:hh:mm:ss< 形式在 IBOutlet 标签中显示 UIDatePicker 输入和现实世界时间的时间差。我的 NSLog 显示了正确的信息,但我很难在标签中显示相同的数据。
我只需要将格式为“2013:07:24 11:05:04”的日期格式化为格式“24-lug-2013”,这是我用来执行此操作的代码: NSDateFormatter *dtF = [[NSDate
您好,我正在尝试格式化我的 NSString。但它不起作用。我尝试了在 stackoverflow 中得到的所有答案,但对我没有任何作用。 NSLog(@"log 1: %@ %@", [dealDe
我有一个字符串如下: 2012-11-01 我想得到一个代表那天的字符串。所以这就是我的处理方式: NSDateFormatter *dateFormatter = [[NSDateForma
我在使用带有 NSDateFormatter 的自定义日期格式化程序将字符串转换为日期时遇到问题。这是一个从今天的日期创建字符串但无法将其转换回 NSDate 的简短示例: NSDateFormatt
我在使用 NSDateFormatter 时遇到了一个奇怪的问题。当然我在这里做错了什么,但我无法弄清楚它是什么,一定是一些小而愚蠢的东西...... 我有一个要格式化的日期。日期是 2012-05-
如何解决这个问题? 第 5 行 它向我显示此错误“无法在 swift 中调用 'stringFromDate' 错误” let today = NSData() let formatter = N
在 Swift 中使用 NSDateFormatter 时遇到问题,有人可以帮忙吗?下面的代码不打印任何内容。 var dateFormatter = NSDateFormatter() printl
我是一名优秀的程序员,十分优秀!