如何在mongoDB中将mongodb ISODate转换为字符串? [英] How to Convert mongodb ISODate to string in mongoDB?

查看:1830
本文介绍了如何在mongoDB中将mongodb ISODate转换为字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在mongo中将我的ISODate命名为ISODate,我只想使用具有特定日期时间格式的字符串格式.

I have my ISODate in mongo as ISODate and I want to just that in string format with a specific datetime format.

这是ISODate:

ISODate("2020-04-24T11:41:47.280Z")

预期结果:

"2020-04-24T11:41:47.280Z"

我只希望在mongodb上发生这种情况,因为我期望许多服务都采用这种格式,并且我不想对所有服务进行更改,因为这是一项繁琐的工作.

I want this to be happened on mongodb only as many of my services are expecting in this format, and I don't want to make changes in all services as its a tedious job.

推荐答案

在尝试以下操作时,我获得了预期的结果.

I got the expected result while i was trying the following.

ISODate("2020-04-24T11:41:47.280Z").toJSON()

这会把字符串还给我

"2020-04-24T11:41:47.280Z"

这篇关于如何在mongoDB中将mongodb ISODate转换为字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆