1、js代碼
var updateClock = function()
{
$scope.clock.now = new Date();
$scope.timenow = deal($scope.clock.now);
};
setInterval(function()
{
$scope.$apply(updateClock)
}, 1000);
var deal = function (x)
{
return x.toDateString().replace(x.getYear(),"") + x.toTimeString().replace("UTC+0800","");
}
2、html代碼
<html lang="en" ng-app="myApp">
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
<div ng-controller="MyController">
<input ng-model="person.name" type="text" placeholder="your name"/>
<hello>hello {{person.name}}</hello><br />
<hr />
<img src="D:\Project\server\src\web\img\logo.jpg" />
<h2>price:{{price}}</h2><h5>限購五件</h5>
<button ng-click="add(1)">+</button>
<button ng-click="subtract(1)">-</button>
<h4>current count:{{total}}</h4>
{{timenow}}
</div>
</body>
</html>
js處理new Date()獲取的時間
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.