This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Created by Chris Lee on 2018/5/25. | |
#import "DateAndTimeCalculateTools.h" | |
@interface DateAndTimeCalculateTools () | |
//不要频繁创建日历对象。 | |
@property(nonatomic, strong) NSCalendar *gregorian; | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//获取当前时间 | |
- (NSString *)currentDateStr{ | |
NSDate *currentDate = [NSDate date];//获取当前时间,日期 | |
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];// 创建一个时间格式化对象 | |
[dateFormatter setDateFormat:@"YYYY/MM/dd hh:mm:ss SS "];//设定时间格式,这里可以设置成自己需要的格式 | |
NSString *dateString = [dateFormatter stringFromDate:currentDate];//将时间转化成字符串 | |
return dateString; | |
} | |
//获取当前时间戳 | |
- (NSString *)currentTimeStr{ |