[英]DatePicker is not returning the correct date. Is it because NSDate defaults to absolute time?
[英]NSDate not returning correct date
我正在像這樣打印 NSDate:
NSDate *date = [NSDate date];
NSString *stringDate = [data description];
現在是 2011 年 7 月 1 日晚上 11:43。 我的 iPod 甚至在頂部欄上也這么說。 但是 stringDate 打印出來:2011-07-02 03:43:46 +0000
這顯然是錯誤的。 我已經使用 NSDate 數百萬次,但從未遇到過這個問題。 有什么問題? 謝謝
您所在地區的時間偏移量是-04:00 ? NSDate 在顯示日期時會自動調整時間偏移量。 嘗試,
NSString *str = [date descriptionWithLocale:[NSLocale currentLocale]];
它會告訴你正確的日期。
您在 GMT -4 時區嗎? 在這種情況下,它給你的結果是正確的,因為2011-07-02 03:43:46 +0000
是2011-07-01 11:43:46 -4000
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.