📜  计算IST:印度标准时间

📅  最后修改于: 2021-04-23 20:33:24             🧑  作者: Mango

给定两个整数HR ,其中HX地点的小时时间, RX地点到印度的距离(以度为单位),任务是在IST中找到当前时间。

UTC(世界标准时间)是24小时制的时间标准,用于同步世界时钟。

例子:

方法:

  • 已知1小时= 60分钟= 360度旋转
  • 1度旋转=(1/360)小时。
  • 2度旋转=(1/360)* 2小时。
  • 因此,广义公式将是:
IST = UTC + (H / 360) * R (UTC = 0 for IST)
IST = ( H / 360 ) * R

答案将以0:00的形式转换,因此IST中的int部分(小时)和float部分将分开,并且float部分乘以60可将其转换为分钟。

下面是上述方法的实现:

C++
// C++ implementation of the approach
#include 
#include 
using namespace std;
  
// Function to calculate Indian Standard Time
void cal_IST(int h, float r)
{
    float IST = (h * r * 1.0) / 360;
  
    // Separate integer part
    int int_IST = (int)IST;
  
    // Separate float part and return ceil value
    int float_IST = ceil((IST - int_IST) * 60);
  
    cout << int_IST << ":" << float_IST;
}
  
// Driver code
int main()
{
  
    // Number of hours (1 - 24)
    int h = 20;
  
    // Rotations in degrees
    float r = 150;
  
    cal_IST(h, r);
  
    return 0;
}


Java
// Java implementation of the approach 
import java.math.*;
  
class GFG
{
    // Function to calculate Indian Standard Time 
    public static void cal_IST(int h, double r) 
    { 
        double IST = (h * r * 1.0) / 360; 
  
        // Separate integer part 
        int int_IST = (int)IST; 
  
        // Separate float part and return ceil value 
        int float_IST = (int)Math.ceil((int)((IST - int_IST) * 60)); 
  
        System.out.println(int_IST + ":" + float_IST); 
    } 
  
    // Driver code 
    public static void main(String[] args) 
    { 
      
        // Number of hours (1 - 24) 
        int h = 20; 
      
        // Rotations in degrees 
        double r = 150; 
      
        cal_IST(h, r); 
    }
} 
  
// This code is contributed by Naman_Garg


Python3
# Python3 implementation of the approach 
from math import ceil
  
# Function to calculate Indian Standard Time 
def cal_IST(h, r) : 
  
    IST = round((h * r * 1.0) / 360, 3); 
  
    # Separate integer part 
    int_IST = int(IST); 
  
    # Separate float part and return ceil value 
    float_IST = ceil((IST - int_IST) * 60); 
  
    print(int_IST, ":", float_IST); 
  
# Driver code 
if __name__ == "__main__" : 
  
    # Number of hours (1 - 24) 
    h = 20; 
  
    # Rotations in degrees 
    r = 150; 
  
    cal_IST(h, r); 
  
# This code is contributed by AnkitRai01


C#
// C# implementation of the approach
using System;
  
class GFG
{
    // Function to calculate Indian Standard Time 
    public static void cal_IST(int h, double r) 
    { 
        double IST = (h * r * 1.0) / 360; 
  
        // Separate integer part 
        int int_IST = (int)IST; 
  
        // Separate float part and return ceil value 
        int float_IST = (int)Math.Floor((
                         double)(IST - int_IST) * 60); 
  
        Console.WriteLine(int_IST + ":" + float_IST); 
    } 
  
    // Driver code 
    public static void Main(String[] args) 
    { 
      
        // Number of hours (1 - 24) 
        int h = 20; 
      
        // Rotations in degrees 
        double r = 150; 
      
        cal_IST(h, r); 
    }
} 
  
// This code is contributed by PrinciRaj1992


输出:
8:20