2018年5月20日.更新,增加Input小于0时,自动跳回昨天的23点。
function timeCode(Input,Speed,Offset){
Input=typeof(Input)=="undefined"?time:Input;
Speed=typeof(Speed)=="undefined"?1:Speed;
Offset=typeof(Offset)=="undefined"?0:Offset;
Input=Input<0?24*60*60+Input:Input;
var Time=Input*Speed+Offset;
var hour=Math.floor(Time/3600); var min=Math.floor(Time/60); var sec=Math.floor(Time%60);
sec=sec<10?"0"+sec:sec; min=min>=60?min%60:min; min=min<10?"0"+min:min; hour=hour<10?"0"+hour:hour;
var ms=(Time%1); ms=ms.toFixed(4); ms=ms.substr(ms.indexOf(".")+1);
return hour+":"+min+":"+sec+"."+ms;
}
timeCode(time,2,0)
timeCode(Input,Speed,Offset)
Input 默认当前时间,可不填;
Speed默认为1倍速,可不填;
Offset默认为无偏移,可不填;
想不显示毫秒就把 +"."+ms 给删掉。
需要倒计时就在Input填 10-time 。
——————————————————
2018年3月18日小修改
增加输入、倍速、偏移三个控制量,方便直接使用滑块控制器替换。
自行控制时间码到办法:
在文本层-源文本 中,按alt键左键点码表,黏贴一下子表达式;
在效果和预设中搜索“控制”,拖拽滑块控制器到文本层;
选中文本层中到效果,可按回车修改名称;
在表达式中,把 Input= 后的time删除,让光标在等于后保持闪烁,点击表达式的小蚊香拖拽到滑块控制器;
完成Input到替换,可以直接使用滑块控制Input
Input=time;
Speed=1;
Offset=0;
Time=Input*Speed+Offset;
hour=Math.floor(Time/3600);
min=Math.floor(Time/60);
min=min>=60?min%60:min;
sec=Math.floor(Time%60);
sec=sec<10?"0"+sec:sec;
min=min<10?"0"+min:min;
hour=hour<10?"0"+hour:hour;
ms=(Time%1);
ms=ms.toFixed(4);
ms=ms.substr(ms.indexOf(".")+1);
text=hour+":"+min+":"+sec+"."+ms;
————————————————————————————
hour=Math.floor(time/3600);
min=Math.floor(time/60);
min=min>=60?min%60:min;
sec=Math.floor(time%60);
sec=sec<10?"0"+sec:sec;
min=min<10?"0"+min:min;
hour=hour<10?"0"+hour:hour;
ms=(time%1);
ms=ms.toFixed(4);
ms=ms.substr(ms.indexOf(".")+1);
text=hour+":"+min+":"+sec+"."+ms;
——————————以前的方法真蠢——————————
2017年3月28日:增加毫秒版本:
fourDecimalPlaces =1;
/*假如需要4位小数,fourDecimalPlaces =1 ,否则填其他*/
function repeat(target, n) {return (new Array(n + 1)).join(target);}
hour=Math.floor(time/3600);
min=Math.floor(time/60);
sec=Math.floor(time%60);
ms=Math.floor(time*1000%1000)+"";
if(min>=60){min=min%60;}
if(sec<10){sec="0"+sec;}
if(min<10){min="0"+min;}
if(hour<10){hour="0"+hour;}
if(fourDecimalPlaces===1){
if(ms.length<4){ms=ms+repeat(0,4-ms.length);}
}
text=hour+":"+min+":"+sec+"."+ms;
————————————————————————————
倒计时版本 tTime是开始的总时间
tTime=3650/*s*/
T=tTime-time;
hour=Math.floor(T/3600);
min=Math.floor(T/60);
sec=Math.floor(T%60);
if(min>=60){min=min%60;}
if(sec<10){sec="0"+sec;}
if(min<10){min="0"+min;}
if(hour<10){hour="0"+hour;}
text=hour+":"+min+":"+sec;
————————————————————————————
下面是干净没注释的版本。
hour=Math.floor(time/3600);
min=Math.floor(time/60);
sec=Math.floor(time%60);
if(min>=60){min=min%60;}
if(sec<10){sec="0"+sec;}
if(min<10){min="0"+min;}
if(hour<10){hour="0"+hour;}
text=hour+":"+min+":"+sec;
————————————————————————————
以前我也是用蒙版来解决时间码的帧,果然没人逼一下是不会认真想这问题的。。。感谢 donap ~
hour=Math.floor(time/3600);
//时间 等于 把一个数字去掉小数只保留整数 (当前秒数 除以 一小时3600秒)
min=Math.floor(time/60);
//分钟 等于 把一个数字去掉小数只保留整数 (当前秒数 除以 一分钟60秒)
sec=Math.floor(time%60);
//秒 等于 把一个数字去掉小数只保留整数 (当前秒数 除以60剩下的余数 )
if(min>=60){min=min%60;}
//假如 (min大于等于60){min等于 min除以60的余数}
if(sec<10){sec="0"+sec;}
if(min<10){min="0"+min;}
if(hour<10){hour="0"+hour;}
//假如 (一个对象的值 小于 10) {这个对象 等于 字符0 加上 这个对象的数值}
text=hour+":"+min+":"+sec;
//text用于指代文本 等于 hour这个对象的值 加 冒号这个字符 加 min这个对象的值 加 冒号这个字符 加 sec这个对象的值
------------------------------------------------------------------------------
-----------------------------------------
-----------------------------------------
© leizingjiu | Powered by LOFTER