本文介绍了如何显示日期格式,如“今天,2014年3月25日15:18”在iOS中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想显示日期,如今天,2014年3月25日15:18
,如果日期是今天的日期。
也期待明天,2014年3月26日15:18
,如果是明天的日期和 2014年3月27日,星期三15:18
,如果是明天的日期之后。
I want to display date like Today, 25 Mar 2014 15:18
, if the date is today's date.Also expecting Tomorrow, 26 Mar 2014 15:18
, if it is tomorrow's date and Wednesday, 27 Mar 2014 15:18
, if it is day after tomorrow's date.
任何人请帮助我。
推荐答案
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setTimeStyle:NSDateFormatterNoStyle];
[dateFormatter setDateStyle:NSDateFormatterMediumStyle];
NSLocale *frLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"];
[dateFormatter setLocale:frLocale];
[dateFormatter setDoesRelativeDateFormatting:YES];
NSDate *date = [NSDate dateWithTimeIntervalSinceNow:60*60*24*1];
NSString *dateString = [dateFormatter stringFromDate:date];
NSLog(@"dateString: %@", dateString);
NSDateFormatter *detailFormatter = [[NSDateFormatter alloc] init];
[detailFormatter setLocale:frLocale];
[detailFormatter setDateFormat:@"dd MMM yyyy HH:mm"];
NSString *detailString = [detailFormatter stringFromDate:date];
NSLog(@"detailString: %@", detailString);
NSString *finalString = [NSString stringWithFormat:@"%@, %@",dateString, detailString];
NSLog(finalString);
这篇关于如何显示日期格式,如“今天,2014年3月25日15:18”在iOS中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!