在linq中显示HH MM SS格式的分钟数

时间:2013-07-26 08:26:36

标签: c# linq

我使用LINQ在几分钟(75)内从数据库中获取值。现在我想使用LINQ将此分钟转换为HH MM SS格式。任何人都可以帮助我。

谢谢。 我尝试使用以下代码,但我没有成功。

TimeSpan tsMinutes;
try
{    
   using (VodafoneDataClassesDataContext vodafoneDataClassesDataContext = new VodafoneDataClassesDataContext())
   {
        vodafoneDataClassesDataContext.Connection.ConnectionString = BECommon.VodafoneConnectionString;
        return (from auditFormsFilledMasters in vodafoneDataClassesDataContext.AuditFormsFilledMasters
        join storeMasters in vodafoneDataClassesDataContext.StoreMasters 
             on auditFormsFilledMasters.StoreId equals storeMasters.Id
        join deskMasters in vodafoneDataClassesDataContext.DeskMasters 
             on auditFormsFilledMasters.DeskId equals deskMasters.Id
        join usersMasters in vodafoneDataClassesDataContext.UserMasters 
             on auditFormsFilledMasters.AuditorId equals usersMasters.Id into tempMaster
        from TempCircleStore in tempMaster.DefaultIfEmpty()
        where auditFormsFilledMasters.StoreId == fieldStoreId
        select new BEAuditFormsFilledMaster
        {
            minutesSpan =  new TimeSpan(0, Convert.ToInt32(auditFormsFilledMasters.LengthofRecordinMin.ToString()), 0),
            tsMinutes = new TimeSpan(0, Convert.ToInt32(auditFormsFilledMasters.LengthofRecordinMin.ToString()), 0),
            LengthofConversation = auditFormsFilledMasters.LengthofRecordinMin.ToString(),
            where auditFormsFilledValues.AuditFormsFilledMasterId == auditFormsFilledMasters.Id
            select auditFormsFilledValues.SelectedScore).Sum(),
        }).ToList<BEAuditFormsFilledMaster>().AsReadOnly();
 }

1 个答案:

答案 0 :(得分:4)

您需要做的是使用TimeSpan.FromMinutes函数和重载的ToString函数:

TimeSpan.FromMinutes(theAmountOfMinutes).ToString(@"hh\:mm\:ss:")