Now to calculate the value of minutes from the above result we will again use the floor operator. Mathematically this is represented as : seconds = seconds % 3600 To calculate the value of minutes we need to first divide the total number of seconds by 3600 and take the remainder. Mathematically this is represented as : hour = seconds // 3600Īfter this we need to calculate the minutes. Since we need the number of hours, we will divide the total number of seconds (n) by the total number of seconds in an hour (3600). It returns the integral part of the quotient. To get the hour value from seconds we will be using the floor division operator (//). This is mathematically represented as : seconds = seconds % (24 * 3600)Ģ4*3600 since one hour has 3600 seconds (60*60) and one day has 24 hours.Īfter this we can proceed and calculate the hour value from seconds. If it does we will divide it with the total number of seconds in a day and take the remainder. We are going to assume that the time in seconds doesn’t exceed the total number of seconds in a day. You need to get the value of hours, minutes and seconds. How do you convert seconds into the preferred format? To write our own conversion function we first need to think about the problem mathematically. Building a Custom function to convert time into hours minutes and seconds But let’s try and write our own program first before we move on to the in-built modules. No doubt python has amazing modules to do the conversion for us. Let’s take some ‘time’ and think about the problem at hand. Moving forwards we will be referring to time in hours, minutes and seconds as time in the preferred format. Don’t worry, this isn’t a boring history tutorial, rather we will be looking at different ways of converting time in seconds to time in hours, minutes, and seconds. In this tutorial, we will be talking about time.
0 Comments
Leave a Reply. |