有没有简单的方法可以将字符串“YYYYMMDDHHMMSS”转换为“YYYY / MM / DD HH:MM:SS”?

例如我有

var date_string = "20121231023350";

我希望输出为
new_date_string = "2012/12/31 02:33:50";

最佳答案

"20121231023350".replace(
    /^(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})$/,
    "$1/$2/$3 $4:$5:$6");  // "2012/12/31 02:33:50"

07-24 17:10