开发者

assign time to variable

开发者 https://www.devze.com 2023-02-08 18:29 出处:网络
this question maybe foolish by me. but i want to understand the standards. I am creating the online exam application. i want to assign the time for each question while its insertion through UI. what

this question maybe foolish by me. but i want to understand the standards.

I am creating the online exam application. i want to assign the time for each question while its insertion through UI. what field i have to keep there (on UI? and in code behind? and in开发者_JS百科 database?) ? Timespan ? or date time ? . if i keep time span then how do i can convert timespan to datetime while loading the set of questions?I am using asp.net mvc and c#


A TimeSpan holds a duration, like 60 seconds. A DateTime holds a fixed date and time. That's what you should use.


When you say "the time" for the question, do you mean how long it should take to answer the question? If so, then you're looking for a duration, so you should use TimeSpan. If you are able to limit this to some number of minutes (with no fractions), then simply use an integer.


TimeSpan is the time elapsed between two DateTimes.

A DateTime is a specific time and date, but has no understanding of time usage.

Therefore DateTime is the correct to use for you.

EDIT

According to your response on another answer, it's the duration you are after, and that is contained inside a TimeSpan. If it's minutes, the easiest approach is to use:

TimeSpan myTimeSpan = TimeSpan.FromMinutes( myUserInput );

EDIT 2

If you want to calculate the time usage, then when opening up the question page store the time somewhere:

DateTime startTime = DateTime.Now;

Then when the question is answered, do the following:

TimeSpan questionDuration = DateTime.Now - startTime;

questionDuration will now contain the time used from opening up the question to answering it.

0

精彩评论

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

关注公众号