Reputation: 3063
Now i'm working on IOS app by swift with Firebase.com as back end
First i tried to put the time by this function
var userHistoryForupdate = ["dealdate":FirebaseServerValue.timestamp()]
userHistoryRef.updateChildValues(userHistoryForupdate as [NSObject : AnyObject], withCompletionBlock: {
(error:NSError?, ref:Firebase!) in
if (error != nil) {
} else {
}
})
And then in the other views i retrieve the time by this function
var tempPubdate = self.pubDataArray[indexPath.row]["dealdate"] as! Double
dateFormatter.dateFormat = "dd MMM yy"
var dealDateAndTime = NSDate(timeIntervalSince1970: tempPubdate)
cell?.historyDate.text = "\(self.dateFormatter.stringFromDate(dealDateAndTime))"
And my cell display
As you see i got 23 JAN 38 not today.
Anyone know how can i get the correct Date from firebase Thanks!
Upvotes: 2
Views: 668
Reputation: 339
timeIntervalSince1970 takes seconds, while the timestamp from firebase is in milliseconds. You can solve it ju by dividing by 1000
let date = NSDate(timeIntervalSince1970: timeStamp / 1000 )
Upvotes: 0
Reputation: 28750
timeIntervalSince1970 takes seconds, while the timestamp from firebase is in milliseconds.
Upvotes: 3