WriteDateTime() public method

Writes a BSON DateTime to the writer.
public WriteDateTime ( long value ) : void
value long The number of milliseconds since the Unix epoch.
return void
コード例 #1
0
 public void TestTwoDateTimes()
 {
     var document = new BsonDocument();
     using (var writer = new BsonDocumentWriter(document))
     {
         writer.WriteStartDocument();
         writer.WriteDateTime("a", 0);
         writer.WriteDateTime("b", 0);
         writer.WriteEndDocument();
     }
     var json = document.ToJson();
     var expected = "{ 'a' : ISODate('1970-01-01T00:00:00Z'), 'b' : ISODate('1970-01-01T00:00:00Z') }".Replace("'", "\""); ;
     Assert.Equal(expected, json);
 }
コード例 #2
0
 public void TestOneNestedDateTime()
 {
     var document = new BsonDocument();
     using (var writer = new BsonDocumentWriter(document))
     {
         writer.WriteStartDocument();
         writer.WriteStartDocument("nested");
         writer.WriteDateTime("a", 0);
         writer.WriteEndDocument();
         writer.WriteEndDocument();
     }
     var json = document.ToJson();
     var expected = "{ 'nested' : { 'a' : ISODate('1970-01-01T00:00:00Z') } }".Replace("'", "\"");
     Assert.AreEqual(expected, json);
 }