SOURCE

var txt = "0000-00-00";
function getStringLength(str) {
  var len = 0;
  var c = 0;
  for (var i = 0; i < str.length; i++) {
    c = str.charCodeAt(i);
    if (c >= 0 && c <= 127) {
      len++;
    } else {
      len += 2;
    }
  }
  return len;
}

console.log(getStringLength(txt));
console 命令行工具 X clear

                    
>
console