代码发送者
NSData *data2 = [self createrandomNSData:8192];NSMutableData *dataToSend =[NSMutableData data];[dataToSend appendBytes:&tag length:sizeof(int)];long long currentTimeStamp = (long long)([[NSDate date] timeIntervalSince1970]*1000.0);[dataToSend appendBytes:¤tTimeStamp length:sizeof(long long)];[dataToSend appendData:data2];NSLog(@"%i || %lld || %lu",tag,currentTimeStamp,(unsigned long)[dataToSend length]);[_udpSocket sendData:dataToSend toHost:@"230.0.0.1" port:_port withTimeout:-1 tag:tag];tag++;
代码接收器
char* dataBytes = [data bytes];int inTag;long long inCurrentTimeStamp;[data getBytes:&inTag length:sizeof(int)];[data getBytes:&inCurrentTimeStamp range:NSMakeRange(sizeof(int),sizeof(long long))];long long currentTimeStamp = (long long)([[NSDate date] timeIntervalSince1970]*1000.0);long long timeStampDiff = currentTimeStamp - inCurrentTimeStamp;self.delay = timeStampDiff;NSLog(@"%i || %lld || %lu",inTag,timeStampDiff,(unsigned long)[data length]);解决方法
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];[dateFormatter setDateFormat:@"MM/dd/yyyy hh:mm:ss"];[dateFormatter setLocale:[[NSLocale alloc] initWithLocaleIDentifIEr:@"en_US_POSIX"]];Nsstring *strSystemTime = [dateFormatter stringFromDate:[NSDate date]];
我遇到了同样的问题并通过设置NSLocale来解决它.我希望这个解决方案也适合你.
总结以上是内存溢出为你收集整理的ios – 多个设备中[NSDate date]的结果不同全部内容,希望文章能够帮你解决ios – 多个设备中[NSDate date]的结果不同所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)