迅速如何将firestore时间戳转换为日期显示
我想将出版日期添加到文章中,但是如何将其修改为时间戳而不是日期显示,我应该在其中添加代码以显示日期。
feedVC
func getDatas(){
if let timestamp = document.get("timestamp") as? Int{
let post = Post(email: email, caption: caption, imageUrl: imageURL, timestamp: timestamp)
self.postArray.append(post)
...
...
...
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as!
...
...
cell.timeLabel.text = String(postArray[indexPath.row].timestamp)
return cell
}
帖子
import Foundation
struct Post{
var email:String
var caption:String
var imageUrl:String
var timestamp:Int
init(email:String,caption:String,imageUrl:String,timestamp:Int) {
self.email = email
self.caption = caption
self.imageUrl = imageUrl
self.timestamp = timestamp
}
}
I want to add the date of publication to the article, but how to modify it is displayed as a timestamp instead of a date, where should I add the code to display the date instead.
FeedVC
func getDatas(){
if let timestamp = document.get("timestamp") as? Int{
let post = Post(email: email, caption: caption, imageUrl: imageURL, timestamp: timestamp)
self.postArray.append(post)
...
...
...
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as!
...
...
cell.timeLabel.text = String(postArray[indexPath.row].timestamp)
return cell
}
post
import Foundation
struct Post{
var email:String
var caption:String
var imageUrl:String
var timestamp:Int
init(email:String,caption:String,imageUrl:String,timestamp:Int) {
self.email = email
self.caption = caption
self.imageUrl = imageUrl
self.timestamp = timestamp
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论