将毫秒转换为分钟C#.NET [英] Convert the milliseconds to minutes C# .NET
问题描述
您好!我需要一些帮助,将毫秒转换为分钟......我不是故意的..
嘿,你这里1秒钟是1000毫秒,60秒是一分钟..算一算..
我只是在问我是否有办法以编程方式转换Thread.Sleep();所以它用几分钟而不是几毫秒来计算。
让我说应用程序要睡35分钟,即35 x 60 = 2 100 000
我希望能够告诉应用程序在几分钟而不是几毫秒内读取,因为35更容易输入和记忆而不是2 100 000,我不知道你,但对我来说它至少是。
所以我需要做的是..
我有我已经展示过的应用程序(在底部) ),当键入/ min文本框时我正在输入以毫秒为单位的值,我希望能够在几分钟内写出它。但是自从Sleep.Thread();只读毫秒(据我所知)我需要帮助改变它又称(也称为)转换它(毫秒到几分钟)
http://i.imgur.com/XAXYv4d.png [ ^ ]
Hello! I would need some help converting milliseconds to minutes.. and I dont mean like..
"Hey here you go 1 second is 1000 milliseconds, 60 seconds is a minute.. Do the math.."
I am simply asking if there was a way I could programatically convert the Thread.Sleep(); so it counts in minutes instead of milliseconds.
Lets say I want the application to sleep for 35 minutes thats 35 x 60 = 2 100 000
I want to be able to tell the application to read in minutes instead of milliseconds because 35 is alot easier to type and remember than 2 100 000, I dont know about you but for me it is atleast.
So what I need to do is..
I have the application which I already showed a picture of(at the bottom), and when typing into the /min textbox I am currently typing in the value in milliseconds, I would like to be able to write it in minutes.. But since the Sleep.Thread(); only reads in milliseconds (as far as I know) I need help to change it aka (Also known as) convert it (The milliseconds to minutes)
http://i.imgur.com/XAXYv4d.png[^]
private void startlbl_Click(object sender, EventArgs e)
{
Process.Start(textBoxFirst.Text);
var firstProcess = Process.Start(textBoxFirst.Text);
int timeOne = Convert.ToInt32(MinTextBoxFirst.Text);
Thread.Sleep(timeOne); // I want to convert timeOne to minutes and not milliseconds
firstProcess.Kill();
}
我的尝试:
我曾尝试查看重载
What I have tried:
Ive tried looking into overloads
推荐答案
Thread.Sleep也接受TimeSpan作为参数。
请参阅 Thread.Sleep Method(TimeSpan)( System.Threading) [ ^ ]
然后你可以把时间设置得几乎你想要的。
例如,您在文本框中将时间写为35:00,然后使用其中一个
TimeSpan.Parse方法来转换时间间隔。
当然,你必须遵循某些规则,所以也许MaskedTextBox可以替代。
Thread.Sleep also accepts TimeSpan as a parameter.
See Thread.Sleep Method (TimeSpan) (System.Threading)[^]
Then you can set the time to almost what you want.
For example, you write the time as 35:00 in the text box and then use one of the
TimeSpan.Parse methods to convert the time interval.
You have to follow certain rules, of course, so maybe a MaskedTextBox can be an alternative.
怎么样
How about
Thread.Sleep(1000 * 60 * Minutes);
这就是我通常做的,它的可读性:)
That's what I usually do, its readable :)
public void ThreadSleepInMinutes(int minutes)
{
Thread.Sleep(new TimeSpan(0, minutes, 0));
}
请参阅:[ ^ ]。
文档是你的朋友。
See: [^].
The documentation is your friend.
这篇关于将毫秒转换为分钟C#.NET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!