Thursday, October 16, 2025
HomeData Modelling & AIProgram to find the time remaining for the day to complete

Program to find the time remaining for the day to complete

Given the current time in the form of HH::MM, where H represents the hours and M, represents the minutes in a 24-hour time format. The task is to calculate the time remaining for the day to complete as HH::MM.
Examples: 
 

Input: HH::MM = 00::01
Output: 23::01

Input: HH::MM = 23::55
Output: 00::05

 

Approach: 
 

  1. Since the total minutes in a 24 hour complete day is 24 * 60 = 1440 minutes
  2. Calculate the time completed in minutes
  3. Calculate the time remaining in the form of minutes as total minutes – time completed
  4. Convert the time remaining in the form of HH::MM

Below is the implementation of the above approach: 
 

CPP




#include <bits/stdc++.h>
using namespace std;
 
// Function to find the remaining time
void remainingTime(int h, int m)
{
    int totalMin, hoursRemaining, minRemaining;
 
    // Formula for total remaining minutes
    // = 1440 - 60h - m
    totalMin = 1440 - 60 * h - m;
 
    // Remaining hours
    hoursRemaining = totalMin / 60;
 
    // Remaining minutes
    minRemaining = totalMin % 60;
 
    cout << hoursRemaining << "::"
         << minRemaining << endl;
}
 
// Driver code
int main()
{
 
    // Current time
    int h = 0, m = 1;
 
    // Get the remaining time
    remainingTime(h, m);
 
    return 0;
}


Java




class GFG
{
 
// Function to find the remaining time
static void remainingTime(int h, int m)
{
    int totalMin, hoursRemaining, minRemaining;
 
    // Formula for total remaining minutes
    // = 1440 - 60h - m
    totalMin = 1440 - 60 * h - m;
 
    // Remaining hours
    hoursRemaining = totalMin / 60;
 
    // Remaining minutes
    minRemaining = totalMin % 60;
 
    System.out.print(hoursRemaining+ "::"
        + minRemaining +"\n");
}
 
// Driver code
public static void main(String[] args)
{
 
    // Current time
    int h = 0, m = 1;
 
    // Get the remaining time
    remainingTime(h, m);
}
}
 
// This code is contributed by Rajput-Ji


Python




# Function to find the remaining time
def remainingTime(h, m):
 
    # Formula for total remaining minutes
    # = 1440 - 60h - m
    totalMin = 1440 - 60 * h - m
 
    # Remaining hours
    hoursRemaining = totalMin // 60
 
    # Remaining minutes
    minRemaining = totalMin % 60
 
    print(hoursRemaining,"::",minRemaining)
 
# Driver code
 
# Current time
h = 0
m = 1
 
# Get the remaining time
remainingTime(h, m)
 
# This code is contributed by mohit kumar 29


C#




// C# program to Number of pairs of lines
// having integer intersection points
using System;
 
class GFG
{
 
    // Function to find the remaining time
    static void remainingTime(int h, int m)
    {
        int totalMin, hoursRemaining, minRemaining;
     
        // Formula for total remaining minutes
        // = 1440 - 60h - m
        totalMin = 1440 - 60 * h - m;
     
        // Remaining hours
        hoursRemaining = totalMin / 60;
     
        // Remaining minutes
        minRemaining = totalMin % 60;
     
        Console.WriteLine(hoursRemaining+ "::"
                            + minRemaining);
    }
     
    // Driver code
    public static void Main()
    {
     
        // Current time
        int h = 0, m = 1;
     
        // Get the remaining time
        remainingTime(h, m);
    }
}
 
// This code is contributed by AnkitRai01


Javascript




<script>
 
// Javascript program to Number of pairs of lines
// having integer intersection points
 
   
    // Function to find the remaining time
    function remainingTime(h, m)
    {
        var totalMin, hoursRemaining, minRemaining;
       
        // Formula for total remaining minutes
        // = 1440 - 60h - m
         
        totalMin = 1440 - 60 * h - m;
       
        // Remaining hours
         
        hoursRemaining = totalMin / 60;
       
        // Remaining minutes
         
        minRemaining = totalMin % 60;
       
        document.write(Math.trunc(hoursRemaining)+
        "::" + minRemaining);
    }
       
    // Driver code
 
       
        // Current time
        var h = 0, m = 1;
       
        // Get the remaining time
        remainingTime(h, m);
         
</script>


Output: 

23::59

 

Time Complexity: O(1)
Auxiliary Space: O(1)

Feeling lost in the world of random DSA topics, wasting time without progress? It’s time for a change! Join our DSA course, where we’ll guide you on an exciting journey to master DSA efficiently and on schedule.
Ready to dive in? Explore our Free Demo Content and join our DSA course, trusted by over 100,000 neveropen!

RELATED ARTICLES

Most Popular

Dominic
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS