zoukankan      html  css  js  c++  java
  • 时间戳转换

    function jsonDateFormat(jsonDate) {
                //json日期格式转换为正常格式
                var jsonDateStr = jsonDate.toString();//此处用到toString()是为了让传入的值为字符串类型,目的是为了避免传入的数据类型不支持.replace()方法
                try {
                    var k = parseInt(jsonDateStr.replace("/Date(", "").replace(")/", ""), 10);
                    if (k < 0) 
                        return null;
    
                    var date = new Date(parseInt(jsonDateStr.replace("/Date(", "").replace(")/", ""), 10));
                    var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
                    var day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
                    var hours = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
                    var minutes = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
                    var seconds = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
                    var milliseconds = date.getMilliseconds();
                    return date.getFullYear() + "-" + month + "-" + day + " " + hours + ":" + minutes + ":" + seconds;
                }
                catch (ex) {
                    return "时间格式转换错误";
                }
    /// <summary>
            /// 时间戳转为C#格式时间
            /// </summary>
            /// <param name=”timeStamp”></param>
            /// <returns></returns>
            private DateTime GetTime(string timeStamp)
            {
                DateTime dtStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
                long lTime = long.Parse(timeStamp + "0000000");
                TimeSpan toNow = new TimeSpan(lTime); return dtStart.Add(toNow);
            }
    /// <summary>
            /// DateTime时间格式转换为Unix时间戳格式
            /// </summary>
            /// <param name=”time”></param>
            /// <returns></returns>
            private int ConvertDateTimeInt(System.DateTime time)
            {
                System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1));
                return (int)(time - startTime).TotalSeconds;
            }

     前端转换

    function CovertToDate(unittime) {
            unittime = unittime.replace("/Date(", "").replace(")/", "");
            var time = unittime.substr(0, unittime.length - 3);
    
            time = time * 1000;
            var jsDate = new Date(time);
            var UnixTimeToDate = jsDate.getFullYear() + '-' + (jsDate.getMonth() + 1) + '-' + jsDate.getDate();
            //+ ' ' + jsDate.getHours() + ':' + jsDate.getMinutes() + ':' + jsDate.getSeconds();
            return UnixTimeToDate;
        }
  • 相关阅读:
    VisualSVN-Server windows 版安装时报错 "Service 'VisualSVN Server' failed to start. Please check VisualSVN Server log in Event Viewer for more details."
    Pytest 单元测试框架之初始化和清除环境
    Pytest 单元测试框架入门
    Python(email 邮件收发)
    Python(minidom 模块)
    Python(csv 模块)
    禅道简介
    2020年最好的WooCommerce主题
    Shopify网上开店教程(2020版)
    WooCommerce VS Magento 2020:哪个跨境电商自建站软件更好?
  • 原文地址:https://www.cnblogs.com/seanjack/p/6702337.html
Copyright © 2011-2022 走看看