【问题标题】:NSDateFormatter return blank for minute if == 0如果 == 0,NSDateFormatter 返回空白分钟
【发布时间】:2012-10-22 16:08:26
【问题描述】:

代码:

NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"m"];
NSLog(@"%@", [formatter stringFromDate:myDate]);

输出:0 如果myDate 的分钟值为0

这很正常,但是如果分钟设置为0如何让它输出空白值而不是0

【问题讨论】:

  • 空白值是什么意思? " """?

标签: macos cocoa nsdate nsdateformatter


【解决方案1】:

NSString * newString = [myString stringByReplacingOccurrencesOfString:@"0" withString:@""];

【讨论】:

  • 这可行,但NSDateFormatter 是否有任何设置可以自动将其设置为“”?
猜你喜欢
  • 2023-04-11
  • 1970-01-01
  • 2011-06-26
  • 2023-01-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-10-13
相关资源
最近更新 更多