开发中关于时间显示问题(今天/昨天/前天/星期几/具体日期)
以今天为基准,显示 今天/昨天/前天(昨天12:12)
离今天一周之内的显示 星期几(星期四)
离今天一周之外的显示 具体日期(15-09-05 12:33)
为了直观方便,直接上代码,有注释。(都写在ViewController中,需要的自己可以将方法拿出去封装到工具类中)
// ViewController.m
// Test
//
// Created by chenqianfeng on 15/9/15.
// Copyright (c) 2015年 chenqianfeng. All rights reserved.
//
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
NSLog(@"%@",[self format:@"2015年09月1日 12时12分12秒"]);
NSLog(@"%@",[self format:@"2015年09月10日 12时12分12秒"]);
NSLog(@"%@",[self format:@"2015年09月14日 12时12分12秒"]);
}
- (NSString *)format:(NSString *)string
{
NSDateFormatter *inputFormatter= [[NSDateFormatter alloc] init];
[inputFormatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"] ];
[inputFormatter setDateFormat:@"yyyy年MM月dd日 HH时mm分ss秒"];
NSDate*input