Hi,
i'm new to programming and i'm writting a simple program, can anyone help me how to check valid time group,
Example :
when following reports are paste on textbox
1. xxxx xxx 2101 xxx xxx. (2101 is time group in GMT)
2. xxxx xxx 2355 xxx xxx. (2355 is time group in GMT)
3. xxxx xxx 0050 xxx xxx. (0050 is time group in GMT)
4. xxxx xxx 0330 xxx xxx. (0330 is time group in GMT)
valid time range is 2100-0300 utc.
how to validate time and highlight the liine 4 as it exceed the time range.
million thanks in advance.
This code works... it's self explanatory.Code:string time = Console.ReadLine(); byte hour = byte.Parse(time[0].ToString() + time[1].ToString()); byte mins = byte.Parse(time[2].ToString() + time[3].ToString()); if (hour == 21 || hour == 22 || hour == 23 || hour == 00 || hour == 01 || hour == 02 || hour == 03) { if (mins < 60 && mins >= 0) { if (hour == 03 && mins > 00) Console.WriteLine("Invalid"); else if (hour == 21 && mins < 01) Console.WriteLine("Invalid"); else Console.WriteLine("Valid"); } else Console.WriteLine("Invalid"); } else Console.WriteLine("Invalid"); Console.ReadLine();
There might be (which I am like 99% sure there is) a more compact version of this code.. but hey.. this one works!
Made it in like 2 mins... should be beginner stuff...
thank you very much.
You are welcome. Glad to help you... if you have any more questions just ask![]()
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks