Secondĭefinition: A second is the base unit of time in the International System of Units (SI). History/origin: The term "minute" is derived from the Latin "pars minuta prima" which means the "first small part." The minute was originally defined as 1/60 of an hour (60 seconds), based on the average period of Earth's rotation relative to the sun, known as a mean solar day.Ĭurrent use: The minute, as a multiple of the second, is used for all manner of measurements of duration, from timing races, measuring cooking or baking times, number of heart beats per minute, to any number of other applications. Under Coordinated Universal Time, a minute can have a leap second, making the minute equal to 61 rather than 60 seconds. Thank you, Techies, I Hope this will be helpful for you.Definition: A minute (symbol: min) is a unit of time based on the second, the base unit of the International System of Units (SI). TimeSpan span = startTime.Subtract ( dateFromString ) Ĭonsole.WriteLine( "Time Difference (seconds): " + Secondsdiff.ToString() ) Ĭonsole.WriteLine( "Time Difference (minutes): " + Minutesdiff.ToString() ) Ĭonsole.WriteLine( "Time Difference (hours): " + Hoursdiff.ToString() ) Ĭonsole.WriteLine( "Time Difference (days): " + Daysdiff.ToString() ) Date in the(yyyy,dd,mm,hh,mm,ss) format String dateString = " 6:19:02 AM" //If Date is in String Format.ĭateTime dateFromString = DateTime.Parse(dateString) //Parse the String to the DateTime Let's just check the following full source code or you can check with the link given here: Compile the Code using System ĭateTime startTime = DateTime.Now //Current Date Ok, so we can get the properties value by its name with the object of the TimeSpan class.Īnd you can use these values wherever you want like as a timer or something like that how much time days or hours left to reach some date. Check out the following the Code Snippet. Ok, let me just tell you how you will get all these values from the TimeSpan. Which become stores inside the TimeSpan and we can easily get those from the TimeSpan easy or not? So, now in our case the startTime.Subtract perform the operation and return the DateTime values which are Day, Hour, Minute, MiliSecond, Seconds. So, properties are one time of object which is set or return the value of the particular variable. Ok, so if you are familiar with the properties of the class then you will understand this thing properly. So, TimeSpan is a class that has properties like Days, Hours, Minutes, Seconds, Milliseconds. So, firstly I will explain TimeSpan in two lines. Ok, so now you have checked to declare the variable of time span and store the value of the difference now what. So, for that check out the following snippet, TimeSpan span = startTime.Subtract ( dateFromString ) //Perform to Find the Difference So, we are using the time span to perform the subtract operation and to get them all differences. am I right? Ok, so let me just check with you you think I am going to just subtract the date like (Date1 - Date2 ) and store it to another DateTime variable. Now, you might think like that what is the short form or the easier form here. DateTime startTime = DateTime.Now //Current Date Follow the following snippet to get the current date. Now, you will see we got the date on which we want to perform the operations now what about the current date. string stringDate = " 6:19:02 AM" //If Date is in String Format.ĭateTime dateFromString = DateTime.Parse(stringDate) //Parse the String to the DateTime So, let's just check out the following snippet to check how the parsing is going to be done for the string to DateTime. So, the simple solution is to Conver it or parse it to the DateTime it is simple right. So, now the situation is something like that the second date on which we want to perform the difference operations is in the string format and the current date is in the DateTime Format. So, we have a DateTime Variable, one is the start date and the second one is the end date. Today, we are not going to discuss too much about the other things like how we were used to finding the difference before I will just directly move to the concept which we are going to use today. Once again I am back with some cool and easy ways to find the difference between two dates in the C#.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |