Denklik sayısını saat, gün ve saat olarak çevirmeye çalışıyorum.Ondalik saatleri DD'ye dönüştürün: HH: MM
Şimdiye kadar sahip olduğum şey, henüz tam orada değil. Eğer bu mantıklı olursa saatlerden günler arasındaki saat sayısını çıkarmak zorundayım?
/// <summary>
/// Converts from a decimal value to DD:HH:MM
/// </summary>
/// <param name="dHours">The total number of hours</param>
/// <returns>DD:HH:MM string</returns>
public static string ConvertFromDecimalToDDHHMM(decimal dHours)
{
try
{
decimal hours = Math.Floor(dHours); //take integral part
decimal minutes = (dHours - hours) * 60.0M; //multiply fractional part with 60
int D = (int)Math.Floor(dHours/24);
int H = (int)Math.Floor(hours);
int M = (int)Math.Floor(minutes);
//int S = (int)Math.Floor(seconds); //add if you want seconds
string timeFormat = String.Format("{0:00}:{1:00}:{2:00}", D, H, M);
return timeFormat;
}
catch (Exception)
{
throw;
}
}
ÇÖZÜM:
/// <summary>
/// Converts from a decimal value to DD:HH:MM
/// </summary>
/// <param name="dHours">The total number of hours</param>
/// <returns>DD:HH:MM string</returns>
public static string ConvertFromDecimalToDDHHMM(decimal dHours)
{
try
{
decimal hours = Math.Floor(dHours); //take integral part
decimal minutes = (dHours - hours) * 60.0M; //multiply fractional part with 60
int D = (int)Math.Floor(dHours/24);
int H = (int)Math.Floor(hours - (D * 24));
int M = (int)Math.Floor(minutes);
//int S = (int)Math.Floor(seconds); //add if you want seconds
string timeFormat = String.Format("{0:00}:{1:00}:{2:00}", D, H, M);
return timeFormat;
}
catch (Exception)
{
throw;
}
}
Sen saatten
(D * 24)
... çıkarmak gerekir
Teşekkürler, çözümümden çok daha az iş. – WraithNath
Ondalıktan ikiye dönüştürme işleminin sorunlara neden olabileceği durumlar var - (örneğin, beklediğinizden daha az bir dakika ile sonuçlanabilir) ama bu kesinlikle basit bir yaklaşım olabilir :) –
Gördüm! Yorum silindi :-). Güzel cevap (hepimiz aynı anda cevap verdik). Hala benim +1'imi aldın. –