How To Find Format (not Validate Against A Particular Format) Of Date With Moment.js
I have a given Date string, which is already formatted by moment.js by someone. I want to get that format. I have checked existing questions and came across this one - check format
Solution 1:
You can use Parse Date Format plug-in:
This plugin extracts the format of a date/time string.
Here an example (anyway it returns MMM D, YYYY
instead of MMM DD, YYYY
):
functiongetMomentDateFormat(input){
return moment.parseFormat(input);
}
var field = { value: "Nov 30, 2017" };
var dateString = field.value; //"Nov 30, 2017"var dateFormat = getMomentDateFormat(dateString);
console.log(dateFormat);
<scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.19.2/moment.min.js"></script><scriptsrc="https://gr2m.github.io/moment-parseformat/moment-parseformat.js"></script>
PS. Do not use scripts directly from https://gr2m.github.io/, refer github repo.
Post a Comment for "How To Find Format (not Validate Against A Particular Format) Of Date With Moment.js"