我的日期很像
$this->db->group_end();
来自后端数据库。 我需要像
一样改变它20160509125119040
在javascript.plz帮帮我
答案 0 :(得分:3)
试试这个:
<script type="text/javascript">
var string = "20160509125119040";
var date = string.substr(0,4) + "-" + string.substr(4,2) + "-" + string.substr(6,2) + " " + string.substr(8,2) + ":" + string.substr(10,2) + ":" + string.substr(12,2);
console.log(date);
</script>
答案 1 :(得分:0)
您可以像这样使用子字符串。 https://jsfiddle.net/7yq6zxLk/
var n = 20160509125119040;
var formatDate = n.substring(0,4) + "-" + n.substring(4,6) + "-" + n.substring(6,8) + " " + n.substring(8,10) + ":" + n.substring(10, 12) + ":" + n.substring(12, 14);
答案 2 :(得分:0)
试试这个:
var dd ="20160509125119040";
var year = dd.substring(0, 4); var month = dd.substring(4).substring(0, 2); var date = dd.substring(6).substring(0, 2)
var hour = dd.substring(8).substring(0, 2); var min = dd.substring(10).substring(0, 2); var sec = dd.substring(12).substring(0, 2)
var finaldate = year+"-"+month+"-"+date+" "+hour+":"+min+":"+ sec;
alert(finaldate)