【发布时间】:2014-09-26 17:14:53
【问题描述】:
我试图弄清楚如何将文本框中的小时、分钟、秒和毫秒值设置为长变量,以便我可以在应用程序中操作时间值。
到目前为止,我尝试的是创建一个名为“workTime”的长变量,但我不确定如何将输入到文本框中的值分配为一段时间。
例如,如果用户输入“00 : 02 : 30 : 000”,我将如何将其分配给变量?
是否可以通过这种方式分配时间值?
任何建议或替代方法将不胜感激。
private void startBtn_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
string wrkString;
string rstString;
int i;
//Assign text box time string to string variables.
wrkString = wrkTbx.Text;
rstString = restTbx.Text;
//Assign text box string value to a date time variable.
DateTime workDt = DateTime.ParseExact(wrkString.Replace(": ", ":").Replace(" :", ":"), "HH:mm:ss:fff", CultureInfo.InvariantCulture);
DateTime restDt = DateTime.ParseExact(rstString.Replace(": ", ":").Replace(" :", ":"), "HH:mm:ss:fff", CultureInfo.InvariantCulture);
StopGoCvs.Background = new SolidColorBrush(Colors.Green);
hornElmt.Play();
// // set up the timer
myTimer = new DispatcherTimer();
myTimer.Interval = new TimeSpan(0, 0, 0, 0, 1);
myTimer.Tick += myTimer_Tick;
//tell timer to stop when it has reached the allocated work time.
if(myTimer.Interval != workDt.TimeOfDay)
{
// start both timers
myTimer.Start();
myStopwatch.Start();
}
else
{
myTimer.Stop();
myStopwatch.Stop();
}
}
【问题讨论】:
标签: c# windows-phone-8 time stopwatch