admin管理员组文章数量:1391943
Is there any function to get the input that was provided to moment()
In the example below, inputDate bees null.
var date = moment("invalid date");
if(!data.isValid()){
return { message: "Invalid date", inputDate: date }
}
I can access the input using internals i.e. date._i
but was wondering if there's any function that would return the input provided to moment constructor.
Is there any function to get the input that was provided to moment()
In the example below, inputDate bees null.
var date = moment("invalid date");
if(!data.isValid()){
return { message: "Invalid date", inputDate: date }
}
I can access the input using internals i.e. date._i
but was wondering if there's any function that would return the input provided to moment constructor.
1 Answer
Reset to default 8You can use creationData()
After a moment object is created, all of the inputs can be accessed with
creationData()
method:moment("2013-01-02", "YYYY-MM-DD", true).creationData() === { input: "2013-01-02", format: "YYYY-MM-DD", locale: Locale obj, isUTC: false, strict: true }
Here a live example:
var date = moment("invalid date", moment.ISO_8601);
console.log(date.creationData().input);
<script src="https://cdnjs.cloudflare./ajax/libs/moment.js/2.19.4/moment.min.js"></script>
As a side note:
- I've used
moment.ISO_8601
in my snippet to prevent Deprecation Warning, as shown here. - Something quite similar was asked (but not a duplicate) was asked here.
本文标签: javascriptFunction to get the input provided to momentjsStack Overflow
版权声明:本文标题:javascript - Function to get the input provided to momentjs - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744755102a2623414.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论