JsonDatetime

ToDatetime

 1 public DateTime JsonDateTimeConvert(string time)
 2         {
 3             //try
 4             //{
 5             if (String.IsNullOrEmpty(time))
 6             {
 7                 return DateTime.Now;
 8             }
 9                 DateTime dt=DateTime.Parse(time);
10                 return dt;
11                 //IsoDateTimeConverter convert = new IsoDateTimeConverter();
12                 //convert.DateTimeFormat = "yyyy-MM-dd HH:mm:ss.fff";
13                 //string ret = JsonConvert.SerializeObject(time, Formatting.Indented, convert);
14                 //return ret;
15             //}
16             //catch (Exception exp)
17             //{
18                 //return null;
19             //}
20         }

FromDatetime

1 public string JsonDateTimeConvert(DateTime time)
2         {
3             DateTime dt = time;
4             dt = dt.ToUniversalTime();
5             TimeSpan ts = dt - DateTime.Parse("1970-01-01");
6             string result = string.Format("\\/Date({0}+0800)\\/", ts.TotalMilliseconds);
7             return result;
8         }

 

posted @ 2017-06-01 14:51  dyfisgod  阅读(134)  评论(0编辑  收藏  举报