带有月份名称的日期 Objective-C

发布于 2024-12-03 16:46:34 字数 89 浏览 2 评论 0原文

我有一个 NSDate 对象,其值例如:“2011-08-26 14:14:51”,我想显示“8 August 2011”如何实现?谢谢。

I have an NSDate object with value for example: "2011-08-26 14:14:51", I want to display "8 August 2011" how to implement it? Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

り繁华旳梦境 2024-12-10 16:46:34
NSDate *date = [NSDate date]; //I'm using this just to show the this is how you convert a date

NSDateFormatter *df = [[NSDateFormatter alloc] init];
[df setDateStyle:NSDateFormatterLongStyle]; // day, Full month and year
[df setTimeStyle:NSDateFormatterNoStyle];  // nothing

NSString *dateString = [df stringFromDate:date]; [df release];
NSDate *date = [NSDate date]; //I'm using this just to show the this is how you convert a date

NSDateFormatter *df = [[NSDateFormatter alloc] init];
[df setDateStyle:NSDateFormatterLongStyle]; // day, Full month and year
[df setTimeStyle:NSDateFormatterNoStyle];  // nothing

NSString *dateString = [df stringFromDate:date]; [df release];
探春 2024-12-10 16:46:34
NSDateFormatter *df = [[[NSDateFormatter alloc] init] autorelease];
[df setDateFormat:@"dd LLLL yyyy"];
NSString *formattedDate = [df stringFromDate:[NSDate date]];
NSDateFormatter *df = [[[NSDateFormatter alloc] init] autorelease];
[df setDateFormat:@"dd LLLL yyyy"];
NSString *formattedDate = [df stringFromDate:[NSDate date]];
度的依靠╰つ 2024-12-10 16:46:34
NSString *dateStr = @"2011-08-26 14:14:51";

//if you have date then, 
NSString *dateStr = [NSString stringWithFormat:@"%@",yourDate];



NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"YYYY-MM-dd HH:mm:ss"];
NSDate *date = [dateFormat dateFromString:dateStr];
[dateFormat setDateFormat:@"MMMM dd, YYYY"];
NSString* temp = [dateFormat stringFromDate:date];

[dateFormat release];



NSLog(@"%@",temp);
NSString *dateStr = @"2011-08-26 14:14:51";

//if you have date then, 
NSString *dateStr = [NSString stringWithFormat:@"%@",yourDate];



NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"YYYY-MM-dd HH:mm:ss"];
NSDate *date = [dateFormat dateFromString:dateStr];
[dateFormat setDateFormat:@"MMMM dd, YYYY"];
NSString* temp = [dateFormat stringFromDate:date];

[dateFormat release];



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