We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent fcec76a commit 04af4dbCopy full SHA for 04af4db
bson/primitive/primitive.go
@@ -10,7 +10,9 @@ package primitive // import "go.mongodb.org/mongo-driver/bson/primitive"
10
11
import (
12
"bytes"
13
+ "encoding/json"
14
"fmt"
15
+ "time"
16
)
17
18
// Binary represents a BSON binary value.
@@ -33,6 +35,11 @@ type Undefined struct{}
33
35
// DateTime represents the BSON datetime value.
34
36
type DateTime int64
37
38
+// MarshalJSON marshal to time type
39
+func (d DateTime) MarshalJSON() ([]byte, error) {
40
+ return json.Marshal(time.Unix(int64(d)/1000, int64(d)%1000*1000000))
41
+}
42
+
43
// Null repreesnts the BSON null value.
44
type Null struct{}
45
0 commit comments