iOS 日期字符串转时间戳
2017-06-03 本文已影响107人
旅途开发者
/**
根据时间获取时间戳
@param formatTime 时间
@param matter 时间格式
@return 时间戳
*/
+(NSInteger)timeSwitchTimestamp:(NSString *)formatTime Formatter:(NSString *)matter{
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateStyle:NSDateFormatterMediumStyle];
[formatter setTimeStyle:NSDateFormatterShortStyle];
[formatter setDateFormat:matter];
NSTimeZone* timeZone = [NSTimeZone timeZoneWithName:@"Asia/Beijing"];
[formatter setTimeZone:timeZone];
NSDate* date = [formatter dateFromString:formatTime];
NSInteger timeSp = [[NSNumber numberWithDouble:[date timeIntervalSince1970]] integerValue];
return timeSp;
}