所以這是我的代碼已經有了:dateWithTimeIntervalSinceNow給傻答案
NSDate *myCustomDate = [NSDate dateWithTimeIntervalSinceNow:10];
NSLog(@"My custom date: %@", myCustomDate);
,並返回:My custom date: 0023-01-23 18:37:17 +0000
。
爲什麼它給出了一個愚蠢的回答,而不是2011年?其他一切都是正確的。
所以這是我的代碼已經有了:dateWithTimeIntervalSinceNow給傻答案
NSDate *myCustomDate = [NSDate dateWithTimeIntervalSinceNow:10];
NSLog(@"My custom date: %@", myCustomDate);
,並返回:My custom date: 0023-01-23 18:37:17 +0000
。
爲什麼它給出了一個愚蠢的回答,而不是2011年?其他一切都是正確的。
嗯,有趣..我完全複製了該代碼並得到My custom date: 2011-01-23 18:44:14 +0000
,看起來正確。也許你的日曆關閉了?當你這樣做時你會得到什麼?
NSDate *myDate = [NSDate date];
NSLog(@"My date: %@", myDate);
NSDate *myCustomDate = [NSDate dateWithTimeIntervalSinceNow:10];
NSLog(@"My custom date: %@", myCustomDate);
您的設備使用的是日曆。
轉到設置/國際/日曆並變回公曆。
我只是試過了代碼,它似乎工作正常:我的自定義日期:2011-01-23 19:45:19 +0100。在TimeZone設置中可能有問題? –
[NSDate date]什麼打印? – Eiko
它現在完美運作。問題是由於某種原因,我的日曆設置爲日語。 – Andrew