从日期字符串中删除年份?
我使用 NSDateFormatter 从我的 NSDate 中获取表示日期的字符串:
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateStyle:NSDateFormatterFullStyle];
return [formatter stringFromDate:date];
NSDateFormatterFullStyle
格式类似于公元 1952 年 4 月 12 日星期二。我可以轻松检查该日期是否与现在是同一年(使用 NSDate-Extensions)。如果是这种情况,我希望删除表示年份的字符串部分。有没有简单的方法可以做到这一点?
I'm using the NSDateFormatter to get a string representing the date from my NSDate:
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateStyle:NSDateFormatterFullStyle];
return [formatter stringFromDate:date];
The NSDateFormatterFullStyle
format is like Tuesday, April 12, 1952 AD. I can easily check if this date is the same year as now (using NSDate-Extensions). If this is the case, I would like the part of the string representing the year to be removed. Is there an easy way to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我没有找到任何解决方案。我最终搜索了该字符串一年,如果存在则将其删除。
I didn't find any solutions for this. I end up searching the string for a year and remove it if it exists.
这是一篇关于您正在寻找的内容的好文章: iO 的日期和时间示例
Here's a good article on what you're looking for: Date and Time Examples for iOs
是:
EEEE
表示星期几,MMMM
表示月份,d
表示月份中的某一天。Yes:
EEEE
represents the day of the week,MMMM
represents the month, andd
represents the day of the month.