嘿我正在创建一个与另一个交互的程序,我正在尝试设置一个计时器!
我想要一个以mm:ss格式计数的计时器
int seconds = 0;
int minutes = 0;
private void timer1_Tick(object sender, EventArgs e)
{
seconds++;
lblView.Text = seconds.ToString();
}
现在,我正处于一个标签在几秒钟内上升的阶段但是,我想要它显示分钟和秒。我查了一下,然后我读了一下TimeSpan https://msdn.microsoft.com/en-us/library/ee372287(v=vs.110).aspx
我遇到过这种方法:
public static double ConvertSecondsToMinutes(double seconds)
{
return TimeSpan.FromSeconds(seconds).TotalMinutes;
}
但不确定如何将其实现到我的代码中。我正在寻找正确的方法来做到这一点。谢谢
答案 0 :(得分:5)
。TimeSpan对象上的.ToString需要格式化程序。
int seconds = 0;
int minutes = 0;
private void timer1_Tick(object sender, EventArgs e)
{
seconds++;
lblView.Text = TimeSpan.FromSeconds(seconds).ToString("mm\\:ss");
}
答案 1 :(得分:1)
DateTime dt = new DateTime.Now;
private void timer1_Tick(object sender, EventArgs e)
{
lblView.Text = string.Format("{0:mm\\:ss}", DateTime.Now - dt);
}
然后你甚至不必增加,你可以确定它是每次之间的确切秒数和分钟数。
答案 2 :(得分:0)
这个怎么样?
create table Trainers
(
TrainerID int identity
, FirstName varchar(25)
, LastName varchar(25)
, CONSTRAINT PK_Trainers PRIMARY KEY CLUSTERED (TrainerID)
)
create table Courses
(
CourseID int identity
, CourseName varchar(50)
, CONSTRAINT PK_Courses PRIMARY KEY CLUSTERED (CourseID)
)
create table TrainerCourses
(
TrainerID int not null
, CourseID int not null
, StartDate date not null
, EndDate date not null
, DailyStartTime time not null
, CONSTRAINT PK_TrainerCourses PRIMARY KEY CLUSTERED (TrainerID, CourseID, StartDate, DailyStartTime)
, CONSTRAINT FK_TrainerCourses_Trainers FOREIGN KEY (TrainerID) REFERENCES Trainers(TrainerID)
, CONSTRAINT FK_TrainerCourses_Courses FOREIGN KEY (CourseID) REFERENCES Courses(CourseID)
)