473,385 Members | 1,582 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Military Time conversion

drg
My assignment is actually encapsulation which is not the problem -- my
program needs to take two military times and calculate the minutes
elapsed between the two. I have everything worked out so far except how
to convert the military time from a string to an int. Or should I be
casting instead?
Student needs help.

thanks,
DRG
Oct 2 '07 #1
4 13132
On Oct 2, 1:04 pm, drg <dr...@sbcglobal.netwrote:
My assignment is actually encapsulation which is not the problem -- my
program needs to take two military times and calculate the minutes
elapsed between the two. I have everything worked out so far except how
to convert the military time from a string to an int. Or should I be
casting instead?

Student needs help.
Use DateTime.ParseExact to convert it to a DateTime, specifying the
format.

You can subtract one DateTime from another to get a TimeSpan
representing the difference between the two.

Jon

Oct 2 '07 #2
I would split your string to two substrings, one for the hours and one for
the minutes. I don't think there is a standard for 1345 or 13:45. Once
split, then I would use integer.TryParse(sHours, out hours); and
integer.TryParse(sMinutes, out minutes);

"drg" wrote:
My assignment is actually encapsulation which is not the problem -- my
program needs to take two military times and calculate the minutes
elapsed between the two. I have everything worked out so far except how
to convert the military time from a string to an int. Or should I be
casting instead?
Student needs help.

thanks,
DRG
Oct 2 '07 #3
drg wrote:
My assignment is actually encapsulation which is not the problem -- my
program needs to take two military times and calculate the minutes
elapsed between the two. I have everything worked out so far except how
to convert the military time from a string to an int. Or should I be
casting instead?
You should be using DateTime.Parse (or possibly DateTime.ParseExact) to
get the DateTime that reflects your first and second time, then just
subtract one from the other and you'll have your TimeSpan. The only
catch may be the handling of military time, but it should work.

example:

DateTime a = DateTime.Parse("10:59:44 PM");
DateTime b = DateTime.Parse("14:12:10");

TimeSpan c = b - a;

Chris.
Oct 2 '07 #4
drg
drg wrote:
My assignment is actually encapsulation which is not the problem -- my
program needs to take two military times and calculate the minutes
elapsed between the two. I have everything worked out so far except how
to convert the military time from a string to an int. Or should I be
casting instead?
Student needs help.

thanks,
DRG
Thanks, guys! This is twice I have used this group as a 'last resort'
and twice you have come through for me. Guess I should check here first
next time.

I had to used the DateTime.ParseExact() in my clsMilitary.cs code and
the DateTime.Parse() in my militaryTimeDiff method in the frmMain.cs
code. Don't know if that is how its suppose to be but it works.

DRG
Oct 3 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Al | last post by:
Hi Is it a function to convert time to and from military time? Thanks
4
by: richardkreidl | last post by:
How would I check to see if the current time(military format) is greater then 07:30AM and the day of the week is Monday-Friday. Pseudo code: If Current_Time > 07:30AM and Current_Day = Monday...
5
by: Scott | last post by:
If I have a datetime sql field with afternoon datetime values like below in DATETIME VALUE, how can I display the time part in ASP as 1:00 PM, instead of 13:00 PM as seen in CURRENT RESULTS below?...
1
by: ApexData | last post by:
Hello Any know how to convert AM/PM Time to 24Hr Time ? Sample Please ! With and without Now(). ThankYou Greg
8
by: Phillip Vong | last post by:
Simple question from a newbie. Using VWD in VB.NET for ASP.NET. I want to format a time value to show in military time only and without the seconds. I know it's not {0:t} or {0:T} but I can not...
3
by: wocosc | last post by:
I have a quick question.. How can get python to take whatever time of day it is, and output it as military time? I already know how to get it to return the specific time.
2
by: Renee Zarazinski | last post by:
I have two fields Time-in & Time-out that are in military time. I have to calculate the difference (to get the total amt. of time spent working) then show the time as clock time. I've only been...
1
luvgis
by: luvgis | last post by:
I'm new to Access so bear with me. I've found several other versions of this question in the forums but no posts that relate to my specific question. I have a table of bus trips with start and end...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.