将总共1000秒转换为[小时,分钟和秒] [英] convert a total of 1000 seconds into [hours and minutes and seconds]
问题描述
我有一个想要构建的视频播放器。
我有一个水平滚动条
I have a video player that I want to build.
i have a horizontal scroll bar
lenghtMovieLoaded = video.Duration; //(Retrieves the length, in seconds, of the video file.)
hScrollBar1.Maximum = (int)Math.Round(lenghtMovieLoaded); //maximum of scrollbar
可以说,我的视频。持续时间总计为1000秒。
现在,我想在标签中显示1- [当前时间] ]视频/和2- [总时间]。
类似于://label2.Text =1- [00:00] / 2- [00:00];
我需要将1000秒转换为分钟=简单部分>>
video.Duration / 60,我有当前的会议记录。
现在......问题是秒部分..我需要在hScrollBar1移动时从0到60增加它们,而不是超过60但是从0到60重新开始,依此类推,并且对轨道准确。
如果我在1分33秒时,秒部分不能是错误的数学技巧。
我不知道要搜索什么谷歌为。我想算的算法......
或者,如果你知道关于这个东西的教程......
我也不是很擅长数学:)嘿 - 我是一个艺术家所以...
帮助?
谢谢。
Lets say, my video.Duration is 1000 sec in total.
Now,in a label i want to show the 1-[current time] of the video /and the 2-[total time].
Something like: //label2.Text = "1-[00:00]/2-[00:00]";
I need to convert 1000 sec into minutes = easy part>>
video.Duration/60 and I have the current minutes.
Now... the problem is the "seconds" part... I need to increment them from 0- 60 while the hScrollBar1 is moving, and not go over 60 but to restart from 0 -60 and so on, AND to be accurate with the track.
If I am at 1min33sec the "sec" part must not be a erroneous mathematical trick.
I do not know what to search in Google for. An algorithm I suppose...
Or, if you know a tutorial about this thing...
Im not very good at math also :) heh - im an artist so...
help?
and thank you.
推荐答案
TimeSpan
struct是你的朋友!
只需按秒计数创建一个新的TimeSpan,并使用其.ToString(formatString)格式化它:
TheTimeSpan
struct is your friend!
Just create a new TimeSpan from the count in seconds, and use its .ToString(formatString) to format it:
TimeSpan elapsed = TimeSpan.FromSeconds(elapsedTimeSecondsCounter);
string elapsedFormatted = elapsed.ToString(@"m\:ss");
int total_seconds = 1000;
int hours = total_seconds / 3600;
int minutes = total_seconds / 60 % 60;
int seconds = total seconds % 60;
这篇关于将总共1000秒转换为[小时,分钟和秒]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!