【问题标题】:How to save current local time stamp in golang and mongo?如何在golang和mongodb中保存当前本地时间戳?
【发布时间】:2022-12-10 00:33:40
【问题描述】:

我需要确保我的时间戳是根据当前时间生成的,这样我可以稍后进行区分。我已经通过 println 确定我的日期以确保我有一个正确的日期。

request.Created, _ = time.Parse(time.RFC3339, time.Now().Format(time.RFC3339))
request.Updated, _ = time.Parse(time.RFC3339, time.Now().Format(time.RFC3339))

我的结构是这样的:

Created      time.Time          `json:"created_at" bson:"created_at"`
    Updated      time.Time          `json:"updated_at" bson:"updated_at"`

然后我打印出正确的 request.Create/request/Update,如下所示:

但是当我检查我的 mongoDb 时,createdAt 和 UpdatedAt 与我打印它的方式不同 在 mongodb 上它是这样的: 你们有建议或解决方案来处理我的系统中的时间戳和我的 mongo 一样吗? 请给我一个建议。 先感谢您

【问题讨论】:

    标签: mongodb datetime go timestamp timestamp-with-timezone


    【解决方案1】:
    package demo;
    
    import java.text.DateFormat;
    import java.text.SimpleDateFormat;
    import java.util.Date;
    
    public class GetDateinJava {
    
     public static void main(String[] args) {
     
     // Create object of SimpleDateFormat class and decide the format
     DateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
     
     //get current date time with Date()
     Date date = new Date();
     
     // Now format the date
     String date1= dateFormat.format(date);
    
     // Print the Date
     System.out.println("Current date and time is " +date1);
     
     }
    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-11-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多