Created
December 6, 2013 04:09
-
-
Save hidayat365/7818428 to your computer and use it in GitHub Desktop.
Contoh penggunaan TimeSpan di c#
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private string HitungUsia(DateTime awal, DateTime akhir) | |
{ | |
TimeSpan selisih = akhir.Subtract(awal); | |
int tahun = Convert.ToInt32(selisih.Days / 365); | |
int bulan = Convert.ToInt32(selisih.Days % 365 / 30); | |
int hari = selisih.Days - tahun * 365 - bulan * 30; | |
return String.Format("Usia {0} tahun {1} bulan {2} hari", tahun, bulan, hari); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment