CSharp examples for System:DateTime Hour
Date Of Diff Hours
using System.Globalization; using System.Text.RegularExpressions; using System.Web; using System.Linq; using System.Collections.Generic; using System;//w w w .j av a2s. c o m public class Main{ public static int DateOfDiffHours(string time, int hours) { if (string.IsNullOrEmpty(time)) return 1; //DateTime dateTime = TypeHelper.StrToDateTime(time, DateTime.Parse("1900-01-01")); DateTime dateTime = DateTime.Parse("1900-01-01"); if (dateTime.ToString("yyyy-MM-dd") == "1900-01-01") return 1; TimeSpan ts = DateTime.Now - dateTime.AddHours(hours); if (ts.TotalHours > int.MaxValue) { return int.MaxValue; } else if (ts.TotalHours < int.MinValue) { return int.MinValue; } return (int)ts.TotalHours; } }