• <tfoot id='C4Ob6'></tfoot>
    <i id='C4Ob6'><tr id='C4Ob6'><dt id='C4Ob6'><q id='C4Ob6'><span id='C4Ob6'><b id='C4Ob6'><form id='C4Ob6'><ins id='C4Ob6'></ins><ul id='C4Ob6'></ul><sub id='C4Ob6'></sub></form><legend id='C4Ob6'></legend><bdo id='C4Ob6'><pre id='C4Ob6'><center id='C4Ob6'></center></pre></bdo></b><th id='C4Ob6'></th></span></q></dt></tr></i><div id='C4Ob6'><tfoot id='C4Ob6'></tfoot><dl id='C4Ob6'><fieldset id='C4Ob6'></fieldset></dl></div>

    • <bdo id='C4Ob6'></bdo><ul id='C4Ob6'></ul>

    <small id='C4Ob6'></small><noframes id='C4Ob6'>

  • <legend id='C4Ob6'><style id='C4Ob6'><dir id='C4Ob6'><q id='C4Ob6'></q></dir></style></legend>

        在 javascript 或 momentjs 中获取给定的日期格式(指定

        时间:2023-09-05

          <i id='wfB3q'><tr id='wfB3q'><dt id='wfB3q'><q id='wfB3q'><span id='wfB3q'><b id='wfB3q'><form id='wfB3q'><ins id='wfB3q'></ins><ul id='wfB3q'></ul><sub id='wfB3q'></sub></form><legend id='wfB3q'></legend><bdo id='wfB3q'><pre id='wfB3q'><center id='wfB3q'></center></pre></bdo></b><th id='wfB3q'></th></span></q></dt></tr></i><div id='wfB3q'><tfoot id='wfB3q'></tfoot><dl id='wfB3q'><fieldset id='wfB3q'></fieldset></dl></div>

        1. <tfoot id='wfB3q'></tfoot>

          <small id='wfB3q'></small><noframes id='wfB3q'>

                <bdo id='wfB3q'></bdo><ul id='wfB3q'></ul>
                  <tbody id='wfB3q'></tbody>
                <legend id='wfB3q'><style id='wfB3q'><dir id='wfB3q'><q id='wfB3q'></q></dir></style></legend>
                  本文介绍了在 javascript 或 momentjs 中获取给定的日期格式(指定格式的字符串)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  给定一个日期字符串,如何获取描述该日期字符串的格式字符串?

                  Given a datestring, how can I get the format string describing that datestring?

                  换一种说法,如果没有传递要使用的显式格式,我如何获取 Date() 或 MomentJS(可能每个都不同,这很好)用来解析该日期字符串的格式字符串?

                  Put another way, how can I get the format string that Date() or MomentJS (might be different for each, that's fine) would use to parse that datestring if one didn't pass an explicit format to use?

                  所以给定 '2016-01-01' 它应该输出类似 'YYYY-MM-DD' 的内容,例如.

                  So given '2016-01-01' it should output something like 'YYYY-MM-DD', for example.

                  (我知道这是一个简单的问题,可能在某处有答案,但很难用简洁的语言表达,所以我只能找到有关如何解析日期字符串或如何显示日期的问题和答案.没有关于如何输出格式本身.)

                  (I am aware this is a simple question and may have an answer somewhere, but it is difficult to word concisely, so I could only find questions and answers about how to parse datestrings or how to display dates. None about how to output the format itself.)

                  推荐答案

                  整合来自 Matt Johnson 的回答的信息,一些评论,以及我自己的贡献.

                  Consolidating information from Matt Johnson's answer, some comments, and my own contribution.

                  使用 Moment.js(版本 2.10.7+),您可以使用 Creation数据 API.Node.js 中的类似内容:

                  With Moment.js (version 2.10.7+), you can use the Creation Data API. Something like this in Node.js:

                  moment('2016-01-01 00:00:00').creationData().format
                  

                  输出

                  'YYYY-MM-DD HH:mm:ss'
                  

                  就像任何日期解析一样,许多日期字符串的格式由于语言环境等因素而存在歧义(例如,在美国和欧洲之间切换月份和日期的顺序).但是上面的方法对我来说已经足够了.

                  Just as any date parsing is, there is ambiguity about the format of many datestrings due to things such as locale (the order of months and days are switched between the US and Europe, for example). But the above method is sufficient for me.

                  这篇关于在 javascript 或 momentjs 中获取给定的日期格式(指定格式的字符串)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:XSLT 格式日期为 MM DD YYYY 下一篇:识别网页中所选文本是否为粗体

                  相关文章

                  最新文章

                    <bdo id='oKlSt'></bdo><ul id='oKlSt'></ul>
                  <i id='oKlSt'><tr id='oKlSt'><dt id='oKlSt'><q id='oKlSt'><span id='oKlSt'><b id='oKlSt'><form id='oKlSt'><ins id='oKlSt'></ins><ul id='oKlSt'></ul><sub id='oKlSt'></sub></form><legend id='oKlSt'></legend><bdo id='oKlSt'><pre id='oKlSt'><center id='oKlSt'></center></pre></bdo></b><th id='oKlSt'></th></span></q></dt></tr></i><div id='oKlSt'><tfoot id='oKlSt'></tfoot><dl id='oKlSt'><fieldset id='oKlSt'></fieldset></dl></div>
                  <legend id='oKlSt'><style id='oKlSt'><dir id='oKlSt'><q id='oKlSt'></q></dir></style></legend>

                    <tfoot id='oKlSt'></tfoot>

                    1. <small id='oKlSt'></small><noframes id='oKlSt'>