Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
192 views
in Technique[技术] by (71.8m points)

c# - How to make the result displayed in minutes?

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:

minutes: seconds

mm: 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();
        }
    }
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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") ;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...