迅速如何将firestore时间戳转换为日期显示

发布于 2025-02-11 07:38:58 字数 1116 浏览 0 评论 0原文

我想将出版日期添加到文章中,但是如何将其修改为时间戳而不是日期显示,我应该在其中添加代码以显示日期。

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文