here's normal javascript code for creating a date timestamp, using double digits for month, day, hour, minute and second, even when the value is between 0-9:
var now = new Date();
var y = now.getFullYear();
var m = now.getMonth()+1; // month is zero based, i.e. january is 0
var d = now.getDate();
var h = now.getHours();
var min = now.getMinutes();
var s = now.getSeconds();
alert(y+(m<=9?'0'+m:m)+(d<=9?'0'+d:d)+(h<=9?'0'+h:h)+(min<=9?'0'+min:min)+(s<=9?'0'+s:s));
// OUTPUT format YYYYMMDDHHMMSS, e.g. 20130104090106 (i.e. 2013-01-04 09:01:06)
to do it in sahi, just add the variable sign (dollar sign) in front of the variable names and use " instead of ':
var $now = new Date();
var $y = $now.getFullYear();
var $m = $now.getMonth()+1;
var $d = $now.getDate();
var $h = $now.getHours();
var $min = $now.getMinutes();
var $s = $now.getSeconds();
...
function foo() {
_setValue(_textbox(67), "DESPATCH_AUTOTEST_" + $y+($m<=9?"0"+$m:$m)+($d<=9?"0"+$d:$d)+($h<=9?"0"+$h:$h)+($min<=9?"0"+$min:$min)+($s<=9?"0"+$s:$s));
}
No comments:
Post a Comment