我正在嘗試在日期中存儲時間。在這種情況下為1.5秒。我將時間存儲在這樣的日期中:NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];[dateFormatter setDateFormat:@"mm:ss.SS"];[dateFormatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0.0]]; NSDate *date1 = [dateFormatter dateFromString:@"00:01.50"];但是,如果我查看調(diào)試區(qū)域,則可以看到date1的值設(shè)置為:date1 = (NSDate *) 0x1dd32b30 2000-01-01 01:00:01 CET誰能告訴我為什么會這樣嗎?
2 回答

PIPIONE
TA貢獻(xiàn)1829條經(jīng)驗(yàn) 獲得超9個贊
嘗試使用NSLog啟用日期將僅以GMT格式返回日期。因此,如果要檢查獲取的時間或日期是否正確,請將date轉(zhuǎn)換為string和NSLog。
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"mm:ss.SS"];
[dateFormatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0.0]];
NSDate *date1 = [dateFormatter dateFromString:@"00:01.50"];
NSString *dateString = [dateFormatter stringFromDate:date1];
NSlog(@"%@",dateString);
- 2 回答
- 0 關(guān)注
- 840 瀏覽
添加回答
舉報
0/150
提交
取消