热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

如何检查是否是时刻()-Howtocheckifismoment()

Ok,soIsawthattocheckifanObjectismomentIneedtocheckwiththemethodmoment.isMoment(ob

Ok, so I saw that to check if an Object is moment I need to check with the method moment.isMoment(obj) but when I try to validate moment().toDate() it tells me that it's false.

好的,所以我看到要检查一个Object是否需要检查方法moment.isMoment(obj),但是当我尝试验证moment()。toDate()时它会告诉我它是假的。

How may I check if an Object is moment whether it's .toDate() or not?

我如何检查对象是否是时刻是否是.toDate()?

moment.isMoment(moment()) // true
moment.isMoment(moment().toDate()) // false

1 个解决方案

#1


5  

A JS Date is a native date object, not a Moment object. So moment.isMoment(...) returns false, because it isn't an instance of Moment.

JS Date是本机日期对象,而不是Moment对象。所以moment.isMoment(...)返回false,因为它不是Moment的实例。

https://momentjs.com/docs/#/displaying/as-Javascript-date/

https://momentjs.com/docs/#/displaying/as-Javascript-date/

How may I check if an Object is moment whether it's .toDate() or not?

我如何检查对象是否是时刻是否是.toDate()?

The way you did in the question. It's correctly returning false.

你在问题中的方式。它正确地返回false。


推荐阅读
author-avatar
可乐加芬达61158
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有