C RUBY-ON-RAILS MYSQL ASP.NET DEVELOPMENT RUBY .NET LINUX SQL-SERVER REGEX WINDOWS ALGORITHM ECLIPSE VISUAL-STUDIO STRING SVN PERFORMANCE APACHE-FLEX UNIT-TESTING SECURITY LINQ UNIX MATH EMAIL OOP LANGUAGE-AGNOSTIC VB6 MSBUILD

# Outputting time in minutes and seconds C++

By : Victoria Torres
Date : November 21 2020, 11:01 PM
fixed the issue. Will look into that further Accept the total time as an integer instead of a string, and then you can divide it by 60 to get whole minutes and modulus of 60 to get the remaining seconds:
code :
``````#include <stdio.h>
#include <string>

int main() {
char snail_name[15] = "";
int time_taken = 0;

printf("\nEnter name of snail: ");
scanf("%15s", snail_name);
printf("Time to finish course:");
scanf("%d", &time_taken);
printf("%s ran the course in %d:%d\n", &snail_name, time_taken / 60, time_taken % 60);

return 0;
}
``````

Share :

## Python: Read text file with time in hour, minutes and seconds; and angle in degree, arc minutes and arc seconds

By : Mr. Robot
Date : March 29 2020, 07:55 AM
To fix the issue you can do Using matplotlib.dates.datestr2num you could easily convert your first column to plottable numbers, but I did not find a function for your second column. You can build a function to process that, though:
code :
``````import numpy as np

def calc_hour( str ):
hour, min, sec = [float(i) for i in str.split(':')]
min += sec/60.
hour += min/60.
return hour

calc_hour = np.vectorize( calc_hour )

def calc_deg( str ):
deg, min, sec = [float(i) for i in str.split(':')]
min += sec/60.
deg += min/60.
return deg

calc_deg = np.vectorize( calc_deg )
``````
``````values = np.loadtxt('tmp.txt', dtype=str)
hours= calc_hour( values[:,0] )
degs =  calc_deg( values[:,1] )
``````
``````hours = array([ 0.10133333,  0.11713889,  0.23825   ,  0.38333333,  0.39730556,
0.39844444,  0.39983333,  0.40102778,  0.40105556,  0.40108333,
0.50836111])

degs = array([-70., -66., -59., -52., -49., -29., -28., -26., -14.,  25.,  30.])
``````
``````import matplotlib.pyplot as plt
plt.plot(hours,degs)
``````

## Converting time, after 60 seconds it is only displaying the minutes. I am trying to display minutes followed by seconds.

By : user2315317
Date : March 29 2020, 07:55 AM
it helps some times How do I display the seconds followed by the minutes like 1:20. Before the 60 seconds it displays the seconds but after the 60 seconds, it displays 1 mins. Following a tutorial but it is not what I am looking for. If you need more information let me know. , You could do like this
code :
``````private String parseDuration(int durationInSeconds) {
return String.format("%02dm :: ", durationInSeconds/60) + String.format("%02ds", durationInSeconds%60);
}
``````

## How to format elapsed time from seconds to hours, minutes, seconds and milliseconds in Python?

By : user2975840
Date : March 29 2020, 07:55 AM
it should still fix some issue How can I format the time elapsed from seconds to hours, mins, seconds? , If you want to include times like 0.232999801636 as in your input:
code :
``````import time
start = time.time()
end = time.time()
hours, rem = divmod(end-start, 3600)
minutes, seconds = divmod(rem, 60)
print("{:0>2}:{:0>2}:{:05.2f}".format(int(hours),int(minutes),seconds))
``````
``````In [12]: def timer(start,end):
....:         hours, rem = divmod(end-start, 3600)
....:         minutes, seconds = divmod(rem, 60)
....:         print("{:0>2}:{:0>2}:{:05.2f}".format(int(hours),int(minutes),seconds))
....:

In [13]: timer(12345.242,12356.434)
00:00:11.19
In [14]: timer(12300.242,12600.5452)
00:05:00.30
In [19]: timer(0.343,86500.8743)
24:01:40.53
In [16]: timer(0.343,865000.8743)
240:16:40.53
In [17]: timer(0,0.232999801636)
00:00:00.23
``````

## Parsing t=1h2m3s(h - hour, m-minutes, s-seconds ) into seconds if order of hours, minutes and seconds are valid

By : 鲁二峰
Date : March 29 2020, 07:55 AM
may help you . I would first check that the order matches then, if it does calculate the time in seconds.
code :
``````function calculateInSeconds(timeStamp) {
var timeInSeconds=0;
console.log("calculateInSeconds timeStamp:"+timeStamp);
if(timeStamp.match(/t=[0-9]*h?[0-9]*m?[0-9]*s?/g).toString()==timeStamp){
timeStamp.replace(/([0-9]+)[h|m|s]/g, function(match, value) {
if (match.indexOf("h") > -1) {
timeInSeconds += value * 60 * 60;
} else if (match.indexOf("m") > -1) {
timeInSeconds += value * 60;
} else if (match.indexOf("s") > -1) {
timeInSeconds += value * 1;
}
});
}
console.log("timeInSeconds"+timeInSeconds);
}
calculateInSeconds("t=1h2m");//3720 valid
calculateInSeconds("t=2m1h");//0 invalid``````

## minutes and seconds function outputting unwanted numbers to end if time contains milliseconds

By : cainho
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , Apply with Math.round() function it will rounded the values.
code :
``````var time = 122.33, // example time (2 minutes, 2 seconds)
mins = ~~(time / 60),
secs = time % 60;

var hrs = ~~(time / 3600),
mins = ~~((time % 3600) / 60),
secs = time % 60;

var ft = "";

if (hrs > 0) {
ft += "" + hrs + ":" + (mins < 10 ? "0" : "");
}
ft += "" + mins + ":" + (secs < 10 ? "0" : "");
ft += "" +Math.round( secs);
console.log(ft);``````