转换dateformat或从date获取dateformat(Convert dateformat or obtain dateformat from date)

编程入门 行业动态 更新时间:2024-10-11 11:21:09
转换dateformat或从date获取dateformat(Convert dateformat or obtain dateformat from date)

我有一个类似于这个“%d-%m-%Y”的日期格式,我需要将此格式传递给Datepicker,但据我所知,Datepicker不允许这种格式。 由于这种格式是由用户引入的,我无法预测将引入哪种格式。

我只有momentjs,jquery,下划线和datepicker来处理这个因为我正在工作的系统是非常严格的(他们不允许我安装新的插件)

MomentJS返回一个Date对象,它不会转换其中的格式字符串,因此我无法检索它或将其解压缩以在datepicker dateformat中使用它。

有没有办法将此unix格式传递给datepicker,或者将类似的字符串转换为“%d-%m-%Y”到“dd-mm-YY”

订单可以是“%Y-%m-%d”的任何内容,也可以是“%Y”的一部分

编辑1:

为了更好地澄清这一点,我需要将此字符串“%d-%m-%Y”转换为此“DD-MM-YYYY”,但符号可以是任何顺序,还有其他符号:

%a%A%b%B%c%d%H%I%j%m%M%p%S%U%W%w%x%X%y%Y%Z %%

I have a dateformat like this one "%d-%m-%Y" and I need to pass this format to Datepicker, but the Datepicker does not allow this format as far as I'm aware. Since this format is introduced by the user, I can not predict wich format will be introduced.

I only have momentjs, jquery, underscore and datepicker to handle this because the system I'm working is quite restrictive (they do not allow me to install new plugins)

MomentJS returns a Date Object, and it does not convert the format string inside it, so I can't retrieve it or extract it to use it in the datepicker dateformat.

Is there a way to pass this unix format to datepicker, or to convert similar strings like this one "%d-%m-%Y" to "dd-mm-YY"

The order could be anything from this "%Y-%m-%d" or just one part of it "%Y"

Edit 1:

To clarify this better, I need to convert from this string "%d-%m-%Y" to this one "DD-MM-YYYY" but the symbols could be in any order, and there are also other symbols:

%a %A %b %B %c %d %H %I %j %m %M %p %S %U %W %w %x %X %y %Y %Z %%

最满意答案

您可以使用moment-strftime插件 ,该插件以该格式了解令牌。

You can use the moment-strftime plugin, which understands tokens in that format.

更多推荐

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

发布评论

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

>www.elefans.com

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