如何让结果在几分钟内显示出来? [英] How to make the result displayed in minutes?

查看:33
本文介绍了如何让结果在几分钟内显示出来?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个代码,它从字典中获取数据并将其写入标签,但它们在标签中.而且我需要这样做,以分钟的格式记录,即:

I have a code that takes the data from the dictionary and writes it into a label, but in which they are. And I need to do so that it is recorded in the format of minutes, that is:

分钟:秒

毫米:ss

这是执行到标签的映射的代码:

Here is the code that performs the mapping to the label:

private void updateRatingLabels2()
    {
        var tops = AllNames2()
          .OrderBy(pair => pair.Value) 
          .ThenBy(pair => pair.Key, StringComparer.Ordinal) 
          .Take(5)   
          .ToArray();


        for (int i = 23; i <= 27; ++i)
            Controls.Find($"label{i}", true).First().Text = "";

        for (int i = 33; i <= 37; ++i)
            Controls.Find($"label{i}", true).First().Text = "";


        for (int i = 0; i < tops.Length; ++i)
        {
            Controls.Find($"label{i + 23}", true).First().Text = tops[i].Key;
            Controls.Find($"label{i + 33}", true).First().Text = tops[i].Value.ToString();
        }
    }

推荐答案

如果字典中的值是一串日期时间,您可以尝试使用 DateTime.Parse,如下所示:

If the value within the dictionary is a string of datetime you could try using DateTime.Parse like this:

var val = tops[i].Value.ToString();
 Controls.Find($"label{i + 33}", true).First().Text = DateTime.Parse(val).ToString("mm:ss") ;

这篇关于如何让结果在几分钟内显示出来?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆