使用moment.js自定义格式(或正则表达式)(Custom format (or regex) with moment.js)

编程入门 行业动态 更新时间:2024-10-28 00:19:18
使用moment.js自定义格式(或正则表达式)(Custom format (or regex) with moment.js)

可以定义一些包含要被moment.js忽略的字符串的自定义格式吗?

我有一个类似如下的日期字符串:

14-Apr [not valid]

我没有可能在通过moment.js之前更改日期,我想知道moment.js是否会提供一种方法来处理像这样的情况。

Moon.js正被pikaday.js库使用,同时由handsontable.js库使用 。

pikaday.js 没有回调,例如onBeforeOpen和handsontable.js也没有提供它。

It is possible to define some custom format containing a string to be ignored by moment.js ?

I have a date string like the following:

14-Apr [not valid]

I do not have the possibility of changing the date before passing it through moment.js and I'm wondering if moment.js would provide a way to deal with cases like this one.

Moment.js is being used by pikaday.js library which at the same time is being used by handsontable.js library.

pikaday.js doesn't have a callback such as onBeforeOpen and handsontable.js doesn't provide it either.

最满意答案

如文档中所述, “Moment的解析器非常宽容”,因此:

moment("14-Apr random text", "DD-MMM");

将被解释为有效日期( 2016-04-14 )。

As stated in the docs "Moment's parser is very forgiving" so:

moment("14-Apr random text", "DD-MMM");

will be interpreted as a valid date (2016-04-14).

更多推荐

本文发布于:2023-08-07 02:16:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1459528.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:自定义   格式   正则表达式   js   moment

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!