0
想读从MongoDB的日期字段在下面的格式如何使用Java
Formate: YYYY-MM-dd HH:mm:ss.SSSSSS
2017-01-23-10.46.07.812000 - DB2
2017-01-23T16:46:07.812Z - Stored in MongoDB (While viewing from GUI tool)
Mon Jan 23 22:16:07 IST 2017 - Result/Reading from MongoDB
// Formatter for the input date
final DateTimeFormatter inputFormat = DateTimeFormatter.ofPattern("EEE MMM dd HH:mm:ss zzz yyyy");
final ZonedDateTime dateFiledParsed = ZonedDateTime.parse(dateFiled.toString(), inputFormat);
final DateTimeFormatter outputFormat3 = DateTimeFormatter.ofPattern("YYYY-MM-dd HH:mm:ss.SSSSSS");
System.out.println(outputFormat3.format(publicationDateParsed));
Result: 2017-01-23 22:16:07.000000
在结果2017年1月23日22时16分07秒读取从MongoDB的日期(时间戳)。 000,而不是000它应该是812(原始值:2017-01-23-10.46.07.812000)
注意:使用MongoDB Java驱动程序3.4。
预先感谢您!
Bharathi
如果它实际上是一个BSON日期(这意味着它在'mongo' shell中查看时显示为'ISODate'),那么解析为java.util.Date的任何东西都是查询的预期输入格式。如果您发送任何其他格式,那么它将不会匹配。除非您了解转换过程,否则请注意使用UTC值而不是本地时间。 –
什么是'dateFiled'或'dateFiled.toString()'的字符串输出? – Seelenvirtuose
@Seelenvirtuose - dateFiled是“日期dateFiled =”某日期“ –