public static int EncodeTime(DateTime d)
		{
			GregorianCalendar calendar = new GregorianCalendar();

			int millisInDay =
				(int)(calendar.GetHour(d) * 3600000 +
				calendar.GetMinute(d) * 60000 +
				calendar.GetSecond(d) * 1000 +
				calendar.GetMilliseconds(d)) * 10;

			return millisInDay;
		}
 public static TimeSpan DateTimeToTimeSpan(DateTime d)
 {
     GregorianCalendar calendar = new GregorianCalendar();
     return new TimeSpan(0, calendar.GetHour(d), calendar.GetMinute(d), calendar.GetSecond(d), (int)calendar.GetMilliseconds(d));
 }