简体   繁体   English

对输出格式使用相同的解析格式

[英]Using same parsing format for output format

With libary moment there is option to bring a array of formating options and momentjs use the best match for parsing the input.使用 libary moment可以选择带来一系列格式化选项,而momentjs使用最佳匹配来解析输入。

For Example:例如:

var date = moment("29-06-1995", ["MM-DD-YYYY", "DD-MM", "DD-MM-YYYY"]);

but what if I want the take the same format that using in parsing for output formating.但是如果我想要采用与解析输出格式相同的格式怎么办。

var dateText = date.format('selected parse')

How do I know which format moment choose to use?我怎么知道moment选择使用哪种格式?

Currently there is no exposed function for getting the chosen format, however there is a "private" field named _f that contains this information.目前没有用于获取所选格式的公开函数,但是有一个名为_f的“私有”字段包含此信息。

var m = moment("29-06-1995", ["MM-DD-YYYY", "DD-MM", "DD-MM-YYYY"]);
m._f  // "DD-MM-YYYY"

If you use this, be careful when updating versions of moment.如果您使用它,请在更新 moment 版本时小心。 Private fields are not guaranteed to be maintained, and could break between versions.私有字段不能保证得到维护,并且可能会在版本之间中断。

I've logged this as a feature request for future moment.js functionality.我已将此记录为未来 moment.js 功能的功能请求

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM