Javacriptで文字列を日付型に変換、現在の時刻を取得するサンプルコード
1.ソースコード
$scope.lacalDate = d.getFullYear()+"-“+((d.getMonth()+1)<10?"0″:"")+(d.getMonth()+1)+"-“+(d.getDate()<10?"0″:"")+d.getDate()+" “+ (d.getHours()+2<10?"0″:"")+(d.getHours()+2)+":"+(d.getMinutes()<10?"0″:"")+d.getMinutes()+":"+ (d.getSeconds()<10?"0″:"")+d.getSeconds();
var str =’2015-03-18 17:13:15′;
str = str.replace(/-/g,"/");
var date = new Date(str );
2.処理関数:
var myDate = new Date();
myDate.getYear();
myDate.getFullYear();
myDate.getMonth();
myDate.getDate();
myDate.getDay();
myDate.getTime();
myDate.getHours();
myDate.getMinutes();
myDate.getSeconds();
myDate.getMilliseconds();
myDate.toLocaleDateString();
var mytime=myDate.toLocaleTimeString();
myDate.toLocaleString( );