dateとcurrentDateを比較するとタイトルに非常に奇妙な反応があります。 次のようなことが起こります: 私はサーバーに照会して日付を取ってから印刷しますので、正しいと思います(そしてすべては問題ありません)。 その後、3時間前に表示されているcurrentDateを表示します。 さて、私はそれを修正し、私は言っている。 でも!私がそれらを比較しようとしているときは、20:59以前の日付しか取らない。日付をcurrentDateと比較するときの不思議な反応Swift
これは私のコード(//dateevent are the dates that I recover from server
)
if dateevent.earlierDate(self.currentDate).isEqualToDate(self.currentDate){
print("All dates \(dateevent)")
if NSCalendar.currentCalendar().isDate(dateevent, equalToDate: self.currentDate, toUnitGranularity: .Day){
print("here is what it passed from server \(dateevent)")
print("here is the current date \(self.currentDate)")
}
}
あるこの私の出力である
All dates 2016-07-28 19:00:00 +0000
here is what it passed from server 2016-07-28 19:00:00 +0000
here is the current date 2016-07-28 13:43:51 +0000
All dates 2016-07-28 19:00:00 +0000
here is what it passed from server 2016-07-28 19:00:00 +0000
here is the current date 2016-07-28 13:43:51 +0000
All dates 2016-07-28 21:00:00 +0000
All dates 2016-07-28 21:00:00 +0000
All dates 2016-07-28 23:30:00 +0000
All dates 2016-07-29 21:00:00 +0000
All dates 2016-07-29 22:30:00 +0000
All dates 2016-07-29 23:00:00 +0000
All dates 2016-07-29 23:00:00 +0000
All dates 2016-07-29 23:30:00 +0000
All dates 2016-07-30 21:00:00 +0000
を、あなたは何ですか? – Larme
私はギリシャにいて、UTC + 02:00 –
を比較する前に 'currentDate'と' dateevent'を表示しています。 'self.currentDate'が変更されたことは明らかです。あなたの最初の行は、 'dateevent.compare(self.currentDate)== OrderedDescending'として表現されやすくなりました。 – fishinear