C# TimeSpan
TimeSpan型の値は、DateTime型の値の差を表します。 TimeSpan.Daysで差の日数がわかります。 1ミリ秒や1ティックでも短いと日数に換算されないようです。 DateTime.Dateの差使うと日付を比較できます。 DateTime today = DateTime.Now; DateTime yesterday = today.AddDays(-1).AddMinutes(1); DateTime tomorrow = today.AddDays(1); Debug.Log("yesterday: " + yesterday); Debug.Log("today: " + today); Debug.Log("tomorrow: " + tomorrow); TimeSpan timeSpan = today - yesterday; Debug.Log("today - yesterday: " + timeSpan.Days); timeSpan = tomorrow - today; Debug.Log("tomorrow - today: " + timeSpan.Days); timeSpan = today.Date - yesterday.Date; Debug.Log("today.Date - yesterday.Date: " + timeSpan.Days); timeSpan = tomorrow.Date - today.Date; Debug.Log("tomorrow.Date - today.Date: " + timeSpan.Days);




コメント
コメントを投稿