【代码笔记】iOS-获得现在的日期

一,代码。

复制代码
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    //调用获得现在日期的函数。
    [self getDateFromLocal];
    
}
#pragma -mark -functions
//获得现在的日期。格式:2015-03-11
-(NSString*)getDateFromLocal{
 
    NSDate *  senddate=[NSDate date];
    NSDateFormatter  *dateformatter=[[NSDateFormatter alloc] init];
    [dateformatter setDateFormat:@"YYYY-MM-dd"];
    NSString *  locationString=[dateformatter stringFromDate:senddate];
    NSLog(@"locationString:%@",locationString);
    return locationString;
    
}
复制代码

 

二,输出。

2015-10-19 13:42:54.112 获得现在的日期[5520:126089] locationString:2015-10-19

 

 

 
 
原文地址:https://www.cnblogs.com/yang-guang-girl/p/5318156.html