如何使用Date.now()修复日期错误

时间:2018-12-29 07:08:37

标签: node.js angular mongodb typescript

我正在使用Date.now()来获取当前日期和时间,但是我不知道我遇到的问题。我使用控制台来检查date.now()是否生成正确时间的场景是这样吗?不幸的是,我在Unix代码值转换中获得了正确的日期,并检查了正确的时间和日期,但是当我将其放入mongoo模式时,它花费了数小时,而存储日期却花费了数小时。但是,当我获得带有日期的对象时,它会返回几小时的日期和时间,但是当我将其与Angular front绑定时,它会向我显示我放置mongoo的正确时间,问题是我无法按日期过滤数据该对象的bcs包含几个小时的返回时间。

这是我在mongoo上推送的打字稿对象

open Core

type error =
  [ `Specific1Error
  | `Specific2Error
  ]

module type General = sig
  type t
  val res : (t, error) Result.t
end

module Make (M: General) = struct
  let res = M.res
end

module Specific1 =
  Make (struct
      type t = string
      let res = Result.Error `Specific1Error
    end)

module Specific2 =
  Make (struct
    type t = int
    let res = Result.Error `Specific2Error
  end)

(* This type expands to
 * (int, [ `Specific1Error | `Specific2Error ]) result
 *)
let res : ('a , error) Result.t =
  let open Result.Monad_infix in
  Specific1.res >>= (fun _ -> Specific2.res)

(* These errors will still compose with others down the line: *)
type error_plus = [error | `More_errors ]

这是mongo模式:

bill = {
    orderArray: [],
    //investment total
    totalActual:0,
    //sale total
    totalSale: 0,
    //investment - sale 
    totalSave: 0,
    quantity: 0,
    date: Date.now()
} 

1 个答案:

答案 0 :(得分:1)

  1. 请检查您的数据库服务器和应用程序是否在同一时区运行
  2. 或从应用程序端将本地时间转换为UTC格式并将其传递给MongoDB