标签:
我用Newtonsoft.Json.dll转换成json,这次是把一个集合转换成json,这个集合里有个DateTime类型的数据,
转换完成后会变成/Date(1286375605000+0800)/这样,请问怎么才能给他转换成时间格式哇
<script type="text/javascript"> function ChangeDateFormat(time) { if (time != null) { var date = new Date(parseInt(time.replace("/Date(", "").replace(")/", ""), 10)); var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1; var currentDate = date.getDate() < 10 ? "0" + date.getDate() : date.getDate(); return date.getFullYear() + "-" + month + "-" + currentDate; } return ""; } window.onload=function(){ alert(ChangeDateFormat("/Date(1286375605000+0800)/")); // do you want ? var date = new Date("Sun Jan 2 00:00:00 UTC+0800 2000"); date.getYear(); //获取当前年份(2位) date.getFullYear(); //获取完整的年份(4位,1970-????) date.getMonth(); //获取当前月份(0-11,0代表1月) date.getDate(); //获取当前日(1-31) date.getDay(); //获取当前星期X(0-6,0代表星期天) date.getTime(); //获取当前时间(从1970.1.1开始的<a href="https://www.baidu.com/s?wd=%E6%AF%AB%E7%A7%92&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1Y1mWRknWR1rHnvPvndryn30ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6KdThsqpZwYTjCEQLGCpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3EPHbsPHDzn1TL" target="_blank" class="baidu-highlight">毫秒</a>数) date.getHours(); //获取当前小时数(0-23) date.getMinutes(); //获取当前分钟数(0-59) date.getSeconds(); //获取当前秒数(0-59) date.getMilliseconds(); //获取当前<a href="https://www.baidu.com/s?wd=%E6%AF%AB%E7%A7%92&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1Y1mWRknWR1rHnvPvndryn30ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6KdThsqpZwYTjCEQLGCpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3EPHbsPHDzn1TL" target="_blank" class="baidu-highlight">毫秒</a>数(0-999) date.toLocaleDateString(); //获取当前日期 var mytime=date.toLocaleTimeString(); //获取当前时间 date.toLocaleString(); //获取日期与时间 alert(date.toLocaleString()); }; </script>
标签:
原文地址:http://www.cnblogs.com/zhujiabin/p/5142616.html