桁数分0をくっつけて、右からX桁を切り取る。
/*
* 現在時刻をyyyy/MM/dd hh:mm:ss.SSS形式で取得
*/
function getDateStr() {
var now = new Date();
var month = conv2deg(now.getMonth()+1);
var date = conv2deg(now.getDate());
var hours = conv2deg(now.getHours());
var minutes = conv2deg(now.getMinutes());
var seconds = conv2deg(now.getSeconds());
var milSec = conv3deg(now.getMilliseconds());
var dateStr = now.getFullYear() + "/" + month + "/" + date + " ";
dateStr += hours + ":" + minutes + ":" + seconds + "." + milSec;
return dateStr;
}
/*
* 時刻の桁あわせ(2桁)
*/
function conv2deg(val){
val = "00"+val;
return val.substr(val.length-2,2);
}
/*
* 時刻の桁あわせ(3桁)
*/
function conv3deg(val){
val = "000"+val;
return val.substr(val.length-3,3);
}
/*
* 現在時刻をyyyy/MM/dd hh:mm:ss.SSS形式で取得
*/
function getDateStr() {
var now = new Date();
var month = conv2deg(now.getMonth()+1);
var date = conv2deg(now.getDate());
var hours = conv2deg(now.getHours());
var minutes = conv2deg(now.getMinutes());
var seconds = conv2deg(now.getSeconds());
var milSec = conv3deg(now.getMilliseconds());
var dateStr = now.getFullYear() + "/" + month + "/" + date + " ";
dateStr += hours + ":" + minutes + ":" + seconds + "." + milSec;
return dateStr;
}
/*
* 時刻の桁あわせ(2桁)
*/
function conv2deg(val){
val = "00"+val;
return val.substr(val.length-2,2);
}
/*
* 時刻の桁あわせ(3桁)
*/
function conv3deg(val){
val = "000"+val;
return val.substr(val.length-3,3);
}