Esempio n. 1
0
 public static void SetTime(DateTime date, DateTime time)
 {
     if (date != null && time != null)
     {
         date.SetHours(time.GetHours());
         date.SetMinutes(time.GetMinutes());
         date.SetSeconds(time.GetSeconds());
         date.SetMilliseconds(time.GetMilliseconds());
     }
 }
Esempio n. 2
0
        public static string ToXrmString(DateTime date)
        {
            // Get a date string from the Date object
            //2011-04-20T14:00:00Z
            // NOTE: we assume that the local date is in fact converted to UTC already
            // This avoids any local browser timezone missmatches with the user settings timezone
            string month = DateTimeEx.PadNumber(date.GetMonth() + 1, 2);
            string day   = DateTimeEx.PadNumber(date.GetDate(), 2);
            string hours = DateTimeEx.PadNumber(date.GetHours(), 2);
            string mins  = DateTimeEx.PadNumber(date.GetMinutes(), 2);
            string secs  = DateTimeEx.PadNumber(date.GetSeconds(), 2);

            return(String.Format("{0}-{1}-{2}T{3}:{4}:{5}Z", date.GetFullYear(), month, day, hours, mins, secs));
        }
Esempio n. 3
0
 public static DateTime AddTimeToDate(DateTime date, string time)
 {
     if (date == null)
     {
         date = DateTime.Now;
     }
     if (time != null)
     {
         DateTime dateWithTime = DateTime.Parse("01 Jan 2000 " + time.Replace(".", ":").Replace("-", ":").Replace(",", ":"));
         DateTime newDate      = new DateTime(date.GetTime());
         if (!Number.IsNaN((Number)((object)dateWithTime)))
         {
             newDate.SetHours(dateWithTime.GetHours());
             newDate.SetMinutes(dateWithTime.GetMinutes());
             newDate.SetSeconds(dateWithTime.GetSeconds());
             newDate.SetMilliseconds(dateWithTime.GetMilliseconds());
             return(newDate);
         }
         return(null);
     }
     return(date);
 }
Esempio n. 4
0
 /// <summary>
 /// Gets the duration since midnight in seconds
 /// </summary>
 /// <param name="date"></param>
 /// <returns></returns>
 public static int GetTimeDuration(DateTime date)
 {
     return((date.GetHours() * (60 * 60)) + (date.GetMinutes() * 60) + (date.GetSeconds()));
 }