开发者

Date with Month name Objective-C

开发者 https://www.devze.com 2023-04-03 17:43 出处:网络
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. NSDate *date = [NSDate date]; //I\'m using this

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.


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];


NSDateFormatter *df = [[[NSDateFormatter alloc] init] autorelease];
[df setDateFormat:@"dd LLLL yyyy"];
NSString *formattedDate = [df stringFromDate:[NSDate date]];


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);
0

精彩评论

暂无评论...
验证码 换一张
取 消