gpt4 book ai didi

angularjs - 在 Angularjs 列表中显示 TimeSpan 类型数据

转载 作者:行者123 更新时间:2023-12-02 21:05:43 25 4
gpt4 key购买 nike

尝试在表格中显示时间,但它以这种格式显示时间

{"Hours":16,"Minutes":8,"Seconds":45,"Milliseconds":0,"Ticks":581250000000,"Days":0,"TotalDays":0.6727430555555556,"TotalHours":16.145833333333332,"TotalMilliseconds":58125000,"TotalMinutes":968.75,"TotalSeconds":58125}

虽然我希望它以这种格式显示

"12:13:20"

在 Html 文件中,我会像这样列出

<table>
<thead>
<tr>
<th>Start Time</th>
<th>End Time</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="item in Festivals">
<td>{{item.StartTime}}</td>
<td>{{item.EndTime}}</td>
</tr>
</tbody>
</table>

我正在初始化数据的 Angular Controller 代码

var app = angular.module('myApp');

app.controller('SeasonCtrl', [
'$scope', '$http', 'seasonService', function ($scope, $http, seasonService) {

$scope.Seasons = [];

seasonService.GetAllSeasons = function () {
seasonService.getSeasons().success(function (data) {
$scope.Seasons = data.data;
})
}

seasonService.GetAllSeasons();

}
]);

我正在向 Angular Controller 发送数据的 C# 代码

public JsonResult GetAllSeasons()
{
var data = _seasonManager.AllSeasons();
if (data != null)
{
var list = data.Select(r => new
{
r.StartTime,
r.EndTime
});

return Json(new { data = list }, JsonRequestBehavior.AllowGet);
}
return null;
}

最佳答案

我刚刚尝试过这个,它解决了我的问题

在 HTML 中

<table>
<thead>
<tr>
<th>Start Time</th>
<th>End Time</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="item in Festivals">
<td ng-bind='timeFunction(item.StartTime)'></td>
<td ng-bind='timeFunction(item.EndTime)'></td>
</tr>
</tbody>
</table>

在 Angular Controller 中

$scope.timeFunction = function (timeObj) {
var min = timeObj.Minutes < 10 ? "0" + timeObj.Minutes : timeObj.Minutes;
var sec = timeObj.Seconds < 10 ? "0" + timeObj.Seconds : timeObj.Seconds;
var hour = timeObj.Hours < 10 ? "0" + timeObj.Hours : timeObj.Hours;
return hour + ':' + min + ':' + sec;
};

关于angularjs - 在 Angularjs 列表中显示 TimeSpan 类型数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36194728/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com