开发者

What variable should I use if I want to save time values?

开发者 https://www.devze.com 2022-12-18 11:30 出处:网络
I want to make an app that adds 1 minutes and 25 seconds to a TimeLeft variable. Problem is I have no idea what type of variable this should be, or even how to add 1 minutes 25 seconds to the availab

I want to make an app that adds 1 minutes and 25 seconds to a TimeLeft variable.

Problem is I have no idea what type of variable this should be, or even how to add 1 minutes 25 seconds to the availab开发者_StackOverflow社区le time left.

Any guidance would be much appreciated. I'm good with C#, but since I've never done something like, I'm in the dark.


I would suggest you use a DateTime variable. This will let you manipulate the time. If you want to add 1m 25s to a varible, you could simply use:

DateTime newTime = DateTime.Now.AddSeconds(85);

That will add 85 seconds onto the current time (or, in your case, TimeLeft as long as the TimeLeft variable is also a DateTime type)


TimeSpan works well. It's specifically designed to hold a duration of time.


Use the DateTime type. Assuming your TimeLeft variable is an integer, you probably need to convert it to DateTime type first and then perform the add. More information here

0

精彩评论

暂无评论...
验证码 换一张
取 消