Skip to content

Instantly share code, notes, and snippets.

@coderChrisLee
coderChrisLee / gist:e710e0de275fd27506fd5b7606945512
Created May 25, 2018 07:24
日期和日历计算常用方法—代码示例参考自苹果官方文档
// Created by Chris Lee on 2018/5/25.
#import "DateAndTimeCalculateTools.h"
@interface DateAndTimeCalculateTools ()
//不要频繁创建日历对象。
@property(nonatomic, strong) NSCalendar *gregorian;
@end
@coderChrisLee
coderChrisLee / gist:6c144039378a57935f347cd5aff73bc6
Created May 21, 2018 11:28
13位时间戳(毫秒)与10位时间戳处理——服务器一般是13位时间戳。
//获取当前时间
- (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{