#pragma mark - 获取时间戳、签名和用户ID
- (void)getTimestampAndSignAndUsers_ID
{
[self getTimestamp];
NSString *tempString = [StartSign stringByAppendingFormat:@"%@", timestampStr];
NSString *endSignString = [MBTipClass md5HexDigest:tempString];
// 转化为大写
signStr = [endSignString uppercaseString];
}
#pragma mark - 获取当前时间
- (void)getTimestamp
{
#if 1
NSDate *date = [NSDate date];
NSTimeInterval time = [date timeIntervalSince1970];
NSString *timeStr = [NSString stringWithFormat:@"%.0f", time];
NSTimeZone *zone = [NSTimeZone timeZoneWithName:@"Asia/Shanghai"];
NSInteger interval = [zone secondsFromGMTForDate:date];
NSDate *localeDate = [date dateByAddingTimeInterval:interval];
NSTimeInterval time1 = [localeDate timeIntervalSince1970];
__unused NSString *timeStr1 = [NSString stringWithFormat:@"%.0f", time1];
timestampStr = timeStr;
#endif
#if 0
NSDate *now = [NSDate date];
NSDateFormatter *df = [[NSDateFormatter alloc]init];//时间戳格式化
df.dateFormat = @"yyyy-MM-dd HH:mm:ss"; // 格式化年月日,时分秒
df.timeZone = [NSTimeZone systemTimeZone];//系统所在时区
NSString *systemTimeZoneStr = [df stringFromDate:now];
df.timeZone = [NSTimeZone defaultTimeZone];//默认时区,貌似和上一个没什么区别
NSString *defaultTimeZoneStr = [df stringFromDate:now];
df.timeZone = [NSTimeZone timeZoneForSecondsFromGMT:8 * 3600];//直接指定时区
NSString *plus8TZStr = [df stringFromDate:now];
df.timeZone = [NSTimeZone timeZoneForSecondsFromGMT:-4*3600];//这就是GMT+0时区了
NSString *gmtTZStr = [df stringFromDate: now];
NSLog(@"Test Time\nSys:%@\nDefault:%@\n+8:%@\nGMT:%@",systemTimeZoneStr,defaultTimeZoneStr,plus8TZStr,gmtTZStr);
NSDate *date = [df dateFromString:systemTimeZoneStr];
timestampStr = [NSString stringWithFormat:@"%.0f", [date timeIntervalSince1970]];
#endif
}
E3814A59-420E-48D5-9E38-7317F941ABBF.png
解决上述类似问题:
B3BBE0BE-EE7B-47D6-814B-CE8B417B52A7.png
网友评论