Click here to Skip to main content
15,913,773 members
Home / Discussions / C#
   

C#

 
GeneralRe: Time conversion Pin
Anka_Ame2-May-07 3:11
Anka_Ame2-May-07 3:11 
GeneralRe: Time conversion Pin
Luc Pattyn2-May-07 4:06
sitebuilderLuc Pattyn2-May-07 4:06 
GeneralRe: Time conversion Pin
Malcolm Smart2-May-07 4:38
Malcolm Smart2-May-07 4:38 
AnswerRe: Time conversion Pin
Malcolm Smart2-May-07 3:31
Malcolm Smart2-May-07 3:31 
GeneralRe: Time conversion Pin
Anka_Ame2-May-07 3:36
Anka_Ame2-May-07 3:36 
GeneralRe: Time conversion Pin
Malcolm Smart2-May-07 3:46
Malcolm Smart2-May-07 3:46 
GeneralRe: Time conversion Pin
Anka_Ame2-May-07 4:21
Anka_Ame2-May-07 4:21 
GeneralRe: Time conversion Pin
Malcolm Smart2-May-07 4:35
Malcolm Smart2-May-07 4:35 
You still haven't posted any code....

I hope this isn't homework I am helping with......

So you have xml file eg:-
<br />
<myxml><br />
   <times open="07:30" close="09:30" /><br />
</myxml><br />


And you want to know how long until it opens. Timespan is the difference between two times. If you want to know how long it is until the shop opens, then you need two things. The current time, and the time it opens.

I am assuming you now have "07:30" stored in a string. I am also assuming that you want to know this information about 'today', and not any day in the future.

C# DateTime class, as has already been mentioned, must have both a date and time portion.

To get the current time :-

System.DateTime currentTime = System.DateTime.Now;

As I am writing this, this will give you:

02/05/2007 15:26:34

OK. That is the time now. You now want to know the time (today) when your shop/office etc opens.

So, take the current datetime (currentTime) and replace the time portion with your time.

System.DateTime openTime = System.DateTime.Parse(currentTime.ToShortDateString() + open + ":00" );

The extra ":00" is because a valid time (I think) needs hours:minutes:seconds and yours ("07:00") doesn't have this.

So you now have currentTime and openTime.

If you get the timespan of these, and use the TotalMinutes member, you get the number of minutes until the shop opens, or the number of minutes it has been open if this number is negative.


TimeSpan open = nowTime - openTime;<br />
int MinutesUntilWeOpen = open.TotalMinutes;


Is this homework or a real requirement? Post what you have tried up until now - it makes understanding your requirement a lot easier.


Regards

Angel
*********************************************


GeneralRe: Time conversion Pin
Anka_Ame2-May-07 5:01
Anka_Ame2-May-07 5:01 
GeneralRe: Time conversion Pin
Malcolm Smart2-May-07 5:02
Malcolm Smart2-May-07 5:02 
GeneralRe: Time conversion Pin
Anka_Ame2-May-07 5:10
Anka_Ame2-May-07 5:10 
GeneralRe: Time conversion Pin
Luc Pattyn2-May-07 5:24
sitebuilderLuc Pattyn2-May-07 5:24 
GeneralRe: Time conversion Pin
Anka_Ame2-May-07 5:36
Anka_Ame2-May-07 5:36 
GeneralRe: Time conversion Pin
Malcolm Smart2-May-07 5:50
Malcolm Smart2-May-07 5:50 
AnswerRe: Time conversion Pin
AFSEKI7-May-07 6:35
AFSEKI7-May-07 6:35 
Generalresult speedy application. Pin
V.2-May-07 2:36
professionalV.2-May-07 2:36 
GeneralRe: result speedy application. Pin
Colin Angus Mackay2-May-07 2:43
Colin Angus Mackay2-May-07 2:43 
GeneralRe: result speedy application. Pin
V.2-May-07 3:09
professionalV.2-May-07 3:09 
AnswerRe: result speedy application. Pin
AFSEKI7-May-07 6:41
AFSEKI7-May-07 6:41 
QuestionNeed solution Pin
DON3452-May-07 2:13
DON3452-May-07 2:13 
AnswerRe: Need solution Pin
Christian Graus2-May-07 2:33
protectorChristian Graus2-May-07 2:33 
GeneralRe: Need solution Pin
DON3452-May-07 2:46
DON3452-May-07 2:46 
GeneralRe: Need solution Pin
Christian Graus2-May-07 10:26
protectorChristian Graus2-May-07 10:26 
AnswerRe: Need solution Pin
Rahul Babu2-May-07 2:54
Rahul Babu2-May-07 2:54 
GeneralRe: Need solution Pin
DON3452-May-07 18:43
DON3452-May-07 18:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.