从日期字符串中删除年份?

发布于 2024-12-27 15:30:48 字数 466 浏览 3 评论 0原文

我使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

淡莣 2025-01-03 15:30:48

我没有找到任何解决方案。我最终搜索了该字符串一年,如果存在则将其删除。

I didn't find any solutions for this. I end up searching the string for a year and remove it if it exists.

忘羡 2025-01-03 15:30:48

这是一篇关于您正在寻找的内容的好文章: iO 的日期和时间示例

Here's a good article on what you're looking for: Date and Time Examples for iOs

卸妝后依然美 2025-01-03 15:30:48

是:

[formatter setDateFormat:@"EEEE, MMMM d"];

EEEE 表示星期几,MMMM 表示月份,d 表示月份中的某一天。

Yes:

[formatter setDateFormat:@"EEEE, MMMM d"];

EEEE represents the day of the week, MMMM represents the month, and d represents the day of the month.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文