【发布时间】:2014-11-20 12:43:35
【问题描述】:
在我的项目中,我们需要将服务器发送时间 (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];
【问题讨论】:
-
你有没有弄清楚是哪一步导致了“空白”结果??
-
(很可能是输入日期与您的日期格式不匹配。或者您很可能会被“NSDateFormater 语言环境功能”所吸引。)
-
举一个你试图解析的字符串的例子。另外,什么是“USBV”?
-
对不起,我在谈论USB端口,我在一家银行工作,这里的一切都受到限制..大多数时候我只会在模拟器上工作,很少有机会直接调试在设备上..