LoginSignup
0
0

More than 5 years have passed since last update.

AE 数値をタイムコード表記に変換

Last updated at Posted at 2018-07-14

numConvertToTimecode

ユーザーがただの数値でフォーム入力する事があるのでそれをタイムコードに変更。
スクリプトではcurrentFormatToTime()やtimeToCurrentFormat()があるがちょっと使えない事情があったので考えてみました。

例えば入力フォームで123456と入力したら0:12:34:56に変更する。

var target = "123456";

function numConvertToTimecode(str) {
    var num = new String(str).replace(/,.;/g, "");
    if( isNaN(num) ){
    alert('これは数値ではありません')
    return false;
    }
    if( num.length > 7){
    alert("num over");
    return false;
    }
    for ( var i = num.length ; i < 7 ; i++){
        num ="0"+num;
    }
    while(num != (num = num.replace(/^(-?\d+)(\d{2})/, "$1:$2")));
    return num;
}

numConvertToTimecode(target)
結果 : 0:12:34:56
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0