zoukankan      html  css  js  c++  java
  • convert-Csharp-DateTime-Ticks-to-js

    <!DOCTYPE html>
    <html>
    <head>
        <script>
            function myFunction() {
                var b = formatDate(636371998735052582);
                document.write(b);
            }
    
            //格式化时间
            function formatDate(ticks) {
                //var ticks = 635556672000000000;
    
                //ticks are in nanotime; convert to microtime
                var ticksToMicrotime = ticks / 10000;
    
                //ticks are recorded from 1/1/1; get microtime difference from 1/1/1/ to 1/1/1970
                var epochMicrotimeDiff = Math.abs(new Date(0, 0, 1).setFullYear(1));
    
                //new date is ticks, converted to microtime, minus difference from epoch microtime
                var now = new Date(ticksToMicrotime - epochMicrotimeDiff);
                var year = now.getFullYear();
                var month = now.getMonth() + 1;
                var date = now.getDate();
                var hour = now.getHours();
                var minute = now.getMinutes();
                var second = now.getSeconds();
                return year + "-" + month + "-" + date + "   " + hour + ":" + minute + ":" + second;
    
            }
    
        </script>
    </head>
    
    <body>
        <button onclick="myFunction()">点击这里</button>
    </body>
    </html>

    显示结果 2017-8-1 15:57:53

  • 相关阅读:
    POJ3481(待完善版本,请看注释)
    Heap_Sort金老师模板
    poj2255(Tree_Recover)
    快慢指针
    Link_List
    Perl_Tkx_Canvas绘图功能函数介绍
    配置管理
    变更管理
    合同管理
    收尾存在的问题
  • 原文地址:https://www.cnblogs.com/ligl/p/7357237.html
Copyright © 2011-2022 走看看