在我的项目中,我们要求将服务器发送时间(EDT)转换为本地时间并在UI上显示。我写了下面的代码,似乎在模拟器中工作得非常好,但是它在设备上显示为空白。
由于安全限制,在我的公司USBV访问被禁用,所以我不能直接在设备上调试.PFB代码即时使用..
NSDateFormatter *formatSelectedTime = [[NSDateFormatter alloc] init];
[formatSelectedTime setDateFormat:@"EEE MMM dd HH:mm:ss zzz yyyy"];
NSTimeZone *sourceTimezone =[NSTimeZone timeZoneWithAbbreviation:@"EDT"];
NSTimeZone *destinationTimeZone = [NSTimeZone localTimeZone];
formatSelectedTime.timeZone = sourceTimezone;
NSDate *filledDateInEDT = [formatSelectedTime dateFromString:fillsDetails.tradeDetails.filledTimeStr];
formatSelectedTime.timeZone = destinationTimeZone;
NSString *filledTimeInLocalString = [formatSelectedTime stringFromDate:filledDateInEDT];
答案 0 :(得分:0)
不确定为什么我的帖子被downvoted,但我发现了问题。我使用自定义字体作为标签,我用来显示转换时间,由于某种原因,它在模拟器上正确显示但不在设备上..我重新添加了字体,一切正常..