ReactiveMongo:需要将java.time.LocalDate转换为ReactiveMongo.bson.BSONDateTime

ReactiveMongo:需要将java.time.LocalDate转换为ReactiveMongo.bson.BSONDateTime,java,mongodb,scala,reactivemongo,play-reactivemongo,Java,Mongodb,Scala,Reactivemongo,Play Reactivemongo,我的要求是只将BSONDateTime设置为特定数据。从java.util.Date中,我找到了准确的数据,但在BSONDateTime中尝试转换时,我的输出是错误的。以下是我的转换代码: val currentDate: LocalDate = LocalDate.now(); val milliSeconds: Long = currentDate.atStartOfDay().atZone(ZoneId.systemDefault()).toInstant().toEpochMilli()

我的要求是只将
BSONDateTime
设置为特定数据。从
java.util.Date
中,我找到了准确的数据,但在
BSONDateTime
中尝试转换时,我的输出是错误的。以下是我的转换代码:

val currentDate: LocalDate = LocalDate.now();
val milliSeconds: Long = currentDate.atStartOfDay().atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
new BSONDateTime(milliSeconds);
输出

方面:2015年10月16日星期五00:00:00

实际:2015年10月15日星期五18:30:00

更新问题

我的基本要求是,我希望使用查询设置和比较mongodb数据中的日期。比如:我的mongodb文档有以下结构

{
 "_id" : ObjectId("561e62892d0000e98ec782c3"),
 "addedOn" : ISODate("2015-10-14T14:11:21.361Z"),
 "expiredOn" : ISODate("2015-10-30T00:00:00.000Z")
}
我的第一个查询要求使用以下代码将过期日期设置为当前日期:

 def currentDateOnly: BSONDateTime = {
  val currentDate: LocalDate = LocalDate.now();
  val milliSeconds: Long = currentDate.atStartOfDay().atZone(ZoneOffset.UTC).toInstant().toEpochMilli();

  logger.info("currentDateOnly Conversion: "+currentDate); 
  new BSONDateTime(milliSeconds);
}
从这段代码中,我找到了上午12点的当前日期。我正在将日期转换为
毫秒
并创建
BSONDateTime
对象,并使用反应式mongo查询设置值,如下所示:

$set(propertyName -> CustomUtility.currentDateOnly) // this is just a set par of update statement.
我的第二个查询要求是使用以下查询匹配“expiredOn”日期:

$doc("expiredOn" $gte CustomUtility.currentDateOnly);
现在,当我在数据库中设置日期时,我的mongo db存储了无效的日期值,我在上面也提到过,如:

输出

方面:2015年10月16日星期五00:00:00

实际:2015年10月15日星期五18:30:00


我需要存储特定数据并将查询与特定日期进行比较

不确定这与
BSONDateTime
本身有关。如果您打印
new java.util.Date(毫秒)
,是否正确。如果没有,则之前存在时间转换问题。@cchantep实际:
Fri Oct 15 2015 18:30:00
值显示在mongodb中。我要问的是,是您通过
新日期
&
毫秒
@cchantep获得的结果。请检查更新的问题。您仍然没有尝试建议的测试