xinyaoxp

c#代码

 public class DateTimeUtil
    {
        /// <summary>
        /// 把json的时间格式还原-服务端
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static string Json2Com(string str)
        {
            str = Regex.Replace(str, @"\\/Date\((\d+)\)\\/", match =>
            {
                DateTime dt = new DateTime(1970, 1, 1);
                dt = dt.AddMilliseconds(long.Parse(match.Groups[1].Value));
                dt = dt.ToLocalTime();
                return dt.ToString("yyyy-MM-dd HH:mm:ss");
            });
            return str;
        }
    }

  javascript客户端代码:

 function showDate(val) {
                 if (val != null) {
                     val = val.replace("\/Date(", "");
                     val = val.replace(")/", "");
                     dt = new Date(Number(val));
                     return dt.toLocaleString();
                 } else {
                     return "";
                 }
             }

  

分类:

技术点:

相关文章:

  • 2022-12-23
  • 2021-12-22
  • 2021-12-22
  • 2021-12-06
  • 2021-12-10
  • 2021-12-08
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-12-20
  • 2021-12-22
  • 2021-12-22
  • 2021-12-22
  • 2021-06-29
  • 2021-12-22
  • 2022-12-23
相关资源
相似解决方案