0
我有数据进入我的应用程序,这是存储在字符串中的日期,如下所示: “2011年1月31日星期二上午10点15分”。我尝试过使用dateFromString,然后NSDateFormatter将其更改为另一种格式(理想情况下,我希望它显示为hh:mm(24小时)dd/mm/yyyy)。我无法找到删除星期几名称的方法,所以每当我尝试打印结果时,它都会显示为空。删除表示日期的存储字符串中的日期名称
NSDateFormatter *df = [[NSDateFormatter alloc] init];
//is EEEE is for weekdays?
[df setDateFormat:@"EEEE-dd-MM-yyyy hh:mm a"];
NSDate *myDate = [df dateFromString:[[_feeds[_currentTableView] objectAtIndex:row] objectForKey:@"created"]];
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"dd-MM-yyyy"];
NSDateFormatter *timeFormat = [[NSDateFormatter alloc] init];
[timeFormat setDateFormat:@"HH:mm"];
NSDate *now = [[NSDate alloc] init];
NSString *theDate = [dateFormat stringFromDate:myDate];
NSString *theTime = [timeFormat stringFromDate:myDate];
NSLog(@"\n"
"theDate: |%@| \n"
"theTime: |%@| \n"
, theDate, theTime);
[dateFormat release];
[timeFormat release];
[now release];
任何人都可以帮忙吗?谢谢
好的,谢谢,我真的不知道从哪里开始。 – TheBestBigAl 2012-02-09 17:45:10