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

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

      JavaScript 日期时间解析

      时间:2023-09-05
        <tbody id='TSbTo'></tbody>
      <tfoot id='TSbTo'></tfoot>

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

            • <i id='TSbTo'><tr id='TSbTo'><dt id='TSbTo'><q id='TSbTo'><span id='TSbTo'><b id='TSbTo'><form id='TSbTo'><ins id='TSbTo'></ins><ul id='TSbTo'></ul><sub id='TSbTo'></sub></form><legend id='TSbTo'></legend><bdo id='TSbTo'><pre id='TSbTo'><center id='TSbTo'></center></pre></bdo></b><th id='TSbTo'></th></span></q></dt></tr></i><div id='TSbTo'><tfoot id='TSbTo'></tfoot><dl id='TSbTo'><fieldset id='TSbTo'></fieldset></dl></div>
                <bdo id='TSbTo'></bdo><ul id='TSbTo'></ul>
                <legend id='TSbTo'><style id='TSbTo'><dir id='TSbTo'><q id='TSbTo'></q></dir></style></legend>
                本文介绍了JavaScript 日期时间解析的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                可能重复:
                如何将字符串转换为日期时间JavaScript 中的格式规范?

                我有一个 json 响应,其中包含一个类似的哈希图;

                I have a json response which contains a hashmap like;

                {"map":{"2012-10-10 03:47:00.0":23.400000000000002,"2012-10-10 03:52:00.0":23.3,"2012-10-10 03:57:00.0":23.3,"2012-10-10 04:02:00.0":23.3,"2012-10-10 04:07:00.0":23.200000000000003,"2012-10-10 04:13:00.0":23.1,"2012-10-10 04:18:00.0":23.1,"2012-10-10 04:23:00.0":23.0,"2012-10-10 04:28:00.0":23.0,"2012-10-10 04:33:00.0":23.0,"2012-10-10 04:38:00.0":22.900000000000002,"2012-10-10 04:43:00.0":22.8,"2012-10-10 04:48:00.0":22.8,"2012-10-10 04:53:00.0":22.700000000000003,"2012-10-10 04:58:00.0":22.6,"2012-10-10 05:03:00.0":22.6,"2012-10-10 05:08:00.0":22.5,"2012-10-10 05:13:00.0":22.5,"2012-10-10 05:18:00.0":22.5,"2012-10-10 05:23:00.0":22.400000000000002}}
                

                我想格式化 json 的日期时间部分,例如;

                I want to format datetime part of json like;

                dd/mm/yyyy HH:mm:ss

                dd/mm/yyyy HH:mm:ss

                假设我把所有的pair元素都这样放置;

                Lets assume I put all pair elements like this;

                var myArr = [["2012-10-10 03:47:00.0", 23.400000000000002], ["2012-10-10 03:52:00.0", 23.3], ....];
                

                然后,我尝试解析日期时间部分,如下所示,我在控制台上得到 Date {Invalid Date}

                Then, I try to parse datetime part like below and I got Date {Invalid Date} on console;

                new Date(myArr[0][0]);
                

                如何格式化这种类型的日期时间.

                How can I format this type of datetime.

                推荐答案

                试试以下:

                new Date(Date.parse(myArr[0][0]));
                

                示例

                使用日期.parse 方法将字符串解析为自 1970 年 1 月 1 日 00:00:00 UTC 以来的毫秒数.取那个毫秒数并再次调用 Date 方法来转动那个时间到一个日期对象中.

                Use the Date.parse method to parse the string into the number of milliseconds since January 1, 1970, 00:00:00 UTC. Take that number of milliseconds and call the Date method once again to turn that time into a date object.

                编辑:

                好吧,对于这种情况,这可能有点难看,但似乎 Firefox 的 -s 和 00.0 存在问题.

                Well this may be a little ugly for this case, but it seems Firefox is having an issue with the -s and the 00.0.

                var myArr = [["2012-10-10 03:47:00.0", 23.400000000000002], ["2012-10-10 03:52:00.0", 23.3]];
                
                var date = convertDateTime(myArr[0][0]);
                console.log(date);
                
                function convertDateTime(dateTime){
                    dateTime = myArr[0][0].split(" ");
                
                    var date = dateTime[0].split("-");
                    var yyyy = date[0];
                    var mm = date[1]-1;
                    var dd = date[2];
                
                    var time = dateTime[1].split(":");
                    var h = time[0];
                    var m = time[1];
                    var s = parseInt(time[2]); //get rid of that 00.0;
                
                    return new Date(yyyy,mm,dd,h,m,s);
                }
                

                示例

                这篇关于JavaScript 日期时间解析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:HTML5 输入类型时间设置值不起作用 下一篇:XSLT 格式日期为 MM DD YYYY

                相关文章

                最新文章

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

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

                <tfoot id='QU9cS'></tfoot>

                  <legend id='QU9cS'><style id='QU9cS'><dir id='QU9cS'><q id='QU9cS'></q></dir></style></legend>

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