0

I have day's time in integer formats like 152947 for (15 hour,29 min and 47 seconds), if I add seconds to that then I have to get integer in same format. eg

152947 + 40 => 153027

I do not want to use any time function, I know can do things like

int add2time(int timenum, int secs_to_add){
  int hour = timenum/10000;
  int minute = (timenum/100)%100;
  int second = (timenum%100);
  secs = hour * 3600 + minute * 60 + second;
  secs += secs_to_add;
  return (secs / 3600)*10000+((secs % 3600)/60)*100 + (secs % 60);
}

but as usual, I am looking for some faster ways to directly manipulate integer.

The problem is similar to below What is the standard way to add N seconds to datetime.time in Python?

Community
  • 1
  • 1
duckduckgo
  • 1,280
  • 1
  • 18
  • 32

0 Answers0