PundutsBLOG
this site the web

Contoh Program Mencari Selisih Waktu dalam C#

Dibawah ini adalah contoh program untuk mencari selisih waktu dengan menggunakan bahasa C#.


using System;

namespace SelisihWaktu_024
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
//
// TODO: Add code to start application here
//

int h1,m1,s1,h2,m2,s2,h3,m3,s3;
Console.Write("Input Jam Awal : ");
h1=Convert.ToInt32(Console.ReadLine());
if(h1<=23)
{
Console.Write("Input Menit Awal : ");
m1=Convert.ToInt32(Console.ReadLine());
Console.Write("Input Detik Awal : ");
s1=Convert.ToInt32(Console.ReadLine());
Console.Write("Input Jam Akhir : ");
h2=Convert.ToInt32(Console.ReadLine());
Console.Write("Input Menit Akhir : ");
m2=Convert.ToInt32(Console.ReadLine());
Console.Write("Input Detik Akhir : ");
s2=Convert.ToInt32(Console.ReadLine());

Console.WriteLine("Waktu Awal Percakapan  = {0}:{1}:{2} ",h1,m1,s1);
Console.WriteLine("Waktu Akhir Percakapan = {0}:{1}:{2} ",h2,m2,s2);


if(s1<=s2 && m1<=m2)
{
if(h1<=h2)
{
s3=s2-s1;
m3=m2-m1;
h3=h2-h1;
Console.WriteLine("\nSelisih Waktu Percakapan = {0}:{1}:{2}",h3,m3,s3);
}
}
if(s1>=s2 && m1<=m2)
{
if(h1<=h2)
{
s3=(s2+60)-s1;
m3=(m2-1)-m1;
h3=h2-h1;
Console.WriteLine("Selisih Waktu Percakapan = {0}:{1}:{2}",h3,m3,s3);

}
}
if(s1>=s2 && m1>=m2)
{
if(h1<=h2)
{
s3=(s2+60)-s1;
m3=(((m2-1)+60)-m1);
h3=(h2-1)-h1;
Console.WriteLine("Selisih Waktu Percakapan = {0}:{1}:{2}",h3,m3,s3);

}
}
if(s1<=s2 && m1>=m2)
{
if(h1<=h2)
{
s3=s2-s1;
m3=((m2-1)+60)-m1;
h3=(h2-1)-h1;
Console.WriteLine("Selisih Waktu Percakapan = {0}:{1}:{2}",h3,m3,s3);

}
}
if(s1<=s2 && m1<=m2)
{
if(h1==h2)
{
s3=s2-s1;
m3=m2-m1;
h3=h2-h1;
Console.WriteLine("Selisih Waktu Percakapan = {0}:{1}:{2}",h3,m3,s3);

}
}
if(s1>=s2 && m1<=m2)
{
if(h1==h2)
{
s3=(s2+60)-s1;
m3=(m2-1)-m1;
h3=h2-h1;
Console.WriteLine("Selisih Waktu Percakapan = {0}:{1}:{2}",h3,m3,s3);

}
}
}
else
{
Console.WriteLine("Data Jam yang Anda Masukkan salah");
}
Console.ReadLine();

}
}
}



0 comments:

Post a Comment

 

W3C Validations

Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Morbi dapibus dolor sit amet metus suscipit iaculis. Quisque at nulla eu elit adipiscing tempor.

Usage Policies