MongoDB 把毫秒級時間修改為秒級時間

2021-09-11 06:06:42 字數 620 閱讀 7851

在mongodb中new date()出來的isodate()都是毫秒級的,如下圖所示:

可是在有時的專案中需要用到秒級,筆者的做法是利用$datetostring$datefromstring,首先用datetostringisodate資料轉換成字串,再用$datefromstring將字串轉換為字串轉換為isodate,其中最重要的是datetostring$datefromstring中的format:"%y-%m-%d %h:%m:%s"

db.mytest.aggregate(}}

} },

})

結果輸出:

Linux獲取毫秒級時間

linux獲取毫秒級時間 moakap 在軟體設計中經常會用到關於時間的處理,用來計算語句 函式的執行時間,這時就需要精確到毫秒甚至是微妙的時間。int gettimeofday struct timeval tv struct timezone tz int settimeofday const ...

Linux獲取毫秒級時間

在軟體設計中經常會用到關於時間的處理,用來計算語句 函式的執行時間,這時就需要精確到毫秒甚至是微妙的時間。int gettimeofday struct timeval tv,struct timezone tz int settimeofday const struct timeval tv,co...

C 時間操作(獲取毫秒級)

使用標準c語言的time函式,可以滿足一般性需要 include include int main void time t t time 0 char tmp 64 strftime tmp,sizeof tmp y m d x a 本年第 j天 z localtime t puts tmp ret...