public static DateTime GetCorrectTime(string[] values, out bool IsDateRequired)
        {
            DateTime TempBellDate;
            TimeSpan TempTime;
            string   datetime, date, time = string.Empty;

            IsDateRequired = true;
            date           = values[4] + "-" + values[5] + "-" + values[6];
            if (Convert.ToInt32(values[4]) == 0 ||
                Convert.ToInt32(values[5]) == 0 ||
                Convert.ToInt32(values[6]) == 0)
            {
                // date = DateTime.Now.Date.ToString("yyyy-MM-dd");
                TempBellDate   = DateTime.Now;
                IsDateRequired = false;
                // Date field should be disabled.
            }
            else
            {
                if (!DateTime.TryParse(date, out TempBellDate))
                {
                    TempBellDate   = DateTime.Now;
                    IsDateRequired = false;
                }
            }

            time = Convert.ToInt32(values[1]).ToString("00") + ":" + Convert.ToInt32(values[2]).ToString("00") + ":" + Convert.ToInt32(values[3]).ToString("00");


            if (!TimeSpan.TryParse(time, out TempTime))
            {
                TempTime = DateTime.Now.TimeOfDay;
            }
            datetime = TempBellDate.ToString("yyyy-MM-dd") + " " + TempTime.ToString();

            DateTime.TryParse(datetime, out TempBellDate);

            return(TempBellDate);
        }
Exemplo n.º 2
0
        private string TimeConvert(TimeSpan inputTime)
        {
            string   temp;
            TimeSpan TempTime;

            if (inputTime.Hours >= 12)
            {
                if (inputTime.Hours > 12)
                {
                    TimeSpan twelveHours = new TimeSpan(12, 0, 0);
                    TempTime = inputTime.Subtract(twelveHours);
                }
                else
                {
                    TempTime = inputTime;
                }
                temp = TempTime.ToString(@"hh\:mm") + "PM";
            }
            else
            {
                temp = inputTime.ToString(@"hh\:mm") + "AM";
            }
            return(temp);
        }