首页 > Web开发 > 详细

convert-Csharp-DateTime-Ticks-to-js

时间:2017-08-14 13:54:12      阅读:276      评论:0      收藏:0      [点我收藏+]
<!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

convert-Csharp-DateTime-Ticks-to-js

原文:http://www.cnblogs.com/ligl/p/7357237.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!