private void button1_Click(object sender, EventArgs e) { //تبدیل تاریخ میلادی به شمسی و قمری if (comboBox1.Text != "" & comboBox1.Text != "" & comboBox1.Text != "" & radioButton3.Checked) { date1 = comboBox3.Text + "/" + comboBox2.Text + "/" + comboBox1.Text; DateTime dt = Convert.ToDateTime(date1); label1.Text = pc.GetYear(dt) + "/" + pc.GetMonth(dt) + "/" + pc.GetDayOfMonth(dt); label9.Text = hc.GetYear(dt) + "/" + hc.GetMonth(dt) + "/" + hc.GetDayOfMonth(dt); label10.Text = dt.Year + "/" + dt.Month + "/" + dt.Day; } // //تبدیل تاریخ شمسی به میلادی و قمری if (comboBox1.Text != "" & comboBox1.Text != "" & comboBox1.Text != "" & radioButton1.Checked) { date1 = comboBox3.Text + "/" + comboBox2.Text + "/" + comboBox1.Text; DateTime dt1 = pc.ToDateTime(int.Parse(comboBox3.Text), int.Parse(comboBox2.Text), int.Parse(comboBox1.Text), 0, 0, 0, 0); label1.Text = date1; label9.Text = hc.GetYear(dt1) + "/" + hc.GetMonth(dt1) + "/" + hc.GetDayOfMonth(dt1); label10.Text = dt1.Year + "/" + dt1.Month + "/" + dt1.Day; } // //تبدیل تاریخ قمری به شمسی و میلادی if (comboBox1.Text != "" & comboBox1.Text != "" & comboBox1.Text != "" & radioButton2.Checked) { date1 = comboBox3.Text + "/" + comboBox2.Text + "/" + comboBox1.Text; DateTime dt2 = hc.ToDateTime(int.Parse(comboBox3.Text), int.Parse(comboBox2.Text), int.Parse(comboBox1.Text), 0, 0, 0, 0); label1.Text = pc.GetYear(dt2) + "/" + pc.GetMonth(dt2) + "/" + pc.GetDayOfMonth(dt2); label9.Text = date1; label10.Text = dt2.Year + "/" + dt2.Month + "/" + dt2.Day; } }
public DateTime?GetDate(string hijriOrGregDate) { HijriCalendar hijriCal = new HijriCalendar(); GregorianCalendar gregCal = new GregorianCalendar(); if (!string.IsNullOrEmpty(hijriOrGregDate)) { string[] date = hijriOrGregDate.Split(','); //var lastEnqueriesDate = new DateTime(int.Parse(date[2]), int.Parse(date[1]), int.Parse(date[0]), persianCal); if (date[3] == "H") { DateTime persianDate = hijriCal.ToDateTime(int.Parse(date[2]), int.Parse(date[1]), int.Parse(date[0]), 0, 0, 0, 0); persianDate = new DateTime(int.Parse(date[2]), int.Parse(date[1]), int.Parse(date[0]), hijriCal); return(persianDate); } else { DateTime persianDate = gregCal.ToDateTime(int.Parse(date[2]), int.Parse(date[1]), int.Parse(date[0]), 0, 0, 0, 0); persianDate = new DateTime(int.Parse(date[2]), int.Parse(date[1]), int.Parse(date[0]), gregCal); return(persianDate); } } else { return(null); } }
public static void HijriTest() { HijriCalendar hCal = new HijriCalendar(); DateTime dTest = hCal.ToDateTime(1008, 06, 15, 0, 0, 0, 0); Assert.Equal(dTest, new DateTime(1600, 1, 1).AddDays(hCal.HijriAdjustment)); }
/// <summary> /// تاریخ شروع ماه رمضان /// <para /> /// چون ممکن است در یک سال شمسی دو شروع ماه رمضان داشته باشیم /// <para /> /// مقدار بازگشتی آرایه است که حداکثر دو آیتم دارد /// </summary> public PersianDateTime[] GetStartDayOfRamadan(int hijriAdjustment) { var result = new List<PersianDateTime>(); var hijriCalendar = new HijriCalendar { HijriAdjustment = hijriAdjustment }; var currentHijriYear = hijriCalendar.GetYear(_dateTime); var startDayOfRamadan1 = new PersianDateTime(hijriCalendar.ToDateTime(currentHijriYear, 9, 1, 0, 0, 0, 0)); result.Add(startDayOfRamadan1); var startDayOfRamadan2 = new PersianDateTime(hijriCalendar.ToDateTime(++currentHijriYear, 9, 1, 0, 0, 0, 0)); if (startDayOfRamadan1.Year == startDayOfRamadan2.Year) result.Add(startDayOfRamadan2); return result.ToArray(); }
public static DateTime?GetDate(string hijriOrGregDate) { HijriCalendar hijriCal = new HijriCalendar(); GregorianCalendar gregCal = new GregorianCalendar(); if (!string.IsNullOrEmpty(hijriOrGregDate)) { string[] date = hijriOrGregDate.Split(','); if (date[3] == "H") { DateTime persianDate = hijriCal.ToDateTime(int.Parse(date[2]), int.Parse(date[1]), int.Parse(date[0]), 0, 0, 0, 0); persianDate = DateTime.ParseExact(date[2] + "/" + date[1] + "/" + date[0], "yyyy/MM/dd", new CultureInfo("ar-SA") /*, hijriCal*/); return(persianDate); } else { DateTime persianDate = gregCal.ToDateTime(int.Parse(date[2]), int.Parse(date[1]), int.Parse(date[0]), 0, 0, 0, 0); persianDate = new DateTime(int.Parse(date[2]), int.Parse(date[1]), int.Parse(date[0]), gregCal); return(persianDate); } } else { return(null); } }
/// <summary> /// Converts Hijri date to Gregorian /// </summary> /// <param name="date">for date param please use the corrent format: "year/month/day-hour:minutes:second"</param> public static DateTime HijriToGregorian(this string date, IncludeTime includeTime) { if (string.IsNullOrEmpty(date)) { throw new ArgumentNullException("input hijri date is null or empty!"); } var dateAndTimeArr = date.Split('-'); var hijriDateArr = dateAndTimeArr[0].Split('/'); var result = HC.ToDateTime(int.Parse(hijriDateArr[0]), int.Parse(hijriDateArr[1]) , int.Parse(hijriDateArr[2]), 0, 0, 0, 0); #region time int hour = DateTime.Now.Hour; int minute = DateTime.Now.Minute; int second = DateTime.Now.Second; if (dateAndTimeArr.Length > 1) { var timeArr = dateAndTimeArr[1]; if (timeArr != string.Empty) { var timeSplits = timeArr.Split(':'); hour = timeSplits.Length > 0 ? int.Parse(timeSplits[0]) : 0; minute = timeSplits.Length > 1 ? int.Parse(timeSplits[1]) : 0; second = timeSplits.Length > 2 ? int.Parse(timeSplits[2]) : 0; } } #endregion switch (includeTime) { case IncludeTime.No: result = result.Date .Add(TimeSpan.Zero); break; case IncludeTime.JustHour: result = result.Date .Add(new TimeSpan(hour, 0, 0)); break; case IncludeTime.HourAndMinute: result = result.Date .Add(new TimeSpan(hour, minute, 0)); break; case IncludeTime.Complete: result = result.Date .Add(new TimeSpan(hour, minute, second)); break; default: break; } return(result); }
protected void DoSave(object sender, ImageClickEventArgs e) { try { msgBox.Text = ""; string strSelectedMonth = txtMonthNo.Text.ToString(); string strSelectedDay = txtDayNo.Text.ToString(); int SelectedMonth; int SelectedDay; Int32.TryParse(strSelectedMonth, out SelectedMonth); Int32.TryParse(strSelectedDay, out SelectedDay); if (SelectedMonth == 0 || SelectedMonth > 12) { msgBox.MessageTextMode = AKP.Web.Controls.Common.MessageMode.Error; msgBox.Text = "ماه معتبر نیست"; return; } if (SelectedDay == 0 || SelectedDay > 31) { msgBox.MessageTextMode = AKP.Web.Controls.Common.MessageMode.Error; msgBox.Text = "روز معتبر نیست"; return; } int ReturnCode = SaveControls("~/Main/Default.aspx?BaseID=" + BaseID); if (NewMode && ReturnCode != -1) { NewMode = false; Code = ReturnCode; ShowDetails(); } if (ReturnCode != -1) { DateTime?EventDate = null; if (cboHCCalendarTypeCode.SelectedValue == "1") { PersianCalendar PCalendar = new PersianCalendar(); EventDate = PCalendar.ToDateTime(1390, SelectedMonth, SelectedDay, 12, 1, 1, 1); } if (cboHCCalendarTypeCode.SelectedValue == "2") { HijriCalendar HCalendar = new HijriCalendar(); EventDate = HCalendar.ToDateTime(1390, SelectedMonth, SelectedDay, 12, 1, 1, 1); } else { EventDate = new DateTime(2011, SelectedMonth, SelectedDay, 12, 1, 1, 1); } BOLEvents EventsBOL = new BOLEvents(); EventsBOL.SaveEventDate(ReturnCode, (DateTime)EventDate); } } catch { } }
public static string ToGregorian(string xCalendarType, string xDateTime) { if (string.IsNullOrWhiteSpace(xDateTime)) { return(null); } xDateTime = xDateTime.Trim(); if (string.IsNullOrWhiteSpace(xDateTime)) { return(null); } var xParts = xDateTime.ToString().Split(' '); var strArrDateParts = xParts[0].Split('/'); DateTime dt = new DateTime(); switch (xCalendarType.ToLower()) { case "hijrighamari": var hijriCalendar = new HijriCalendar(); dt = hijriCalendar.ToDateTime( int.Parse(strArrDateParts[0]), int.Parse(strArrDateParts[1]), int.Parse(strArrDateParts[2]), 0, 0, 0, 0); dt = Convert.ToDateTime(dt.ToString()); break; case "hijrishamsi": var persianCalendar = new PersianCalendar(); dt = persianCalendar.ToDateTime( int.Parse(strArrDateParts[0]), int.Parse(strArrDateParts[1]), int.Parse(strArrDateParts[2]), 0, 0, 0, 0); dt = Convert.ToDateTime(dt.ToString()); break; default: return(null); } var time = ""; if (xParts.Length == 2) { time = xParts[1]; } return(dt.Year.ToString("0000") + "/" + dt.Month.ToString("00") + "/" + dt.Day.ToString("00") + (!string.IsNullOrWhiteSpace(time) ? " " + time : "")); }
public static string Convert_Hijry_To_Milady(string date) { int year = -1; int month = -1; int day = -1; try { try { string str = date; char[] separator = new char[1]; int index = 0; int num5 = 0x2f; separator[index] = (char)num5; year = int.Parse(str.Split(separator)[0]); } catch { } try { string str2 = date; char[] chArray2 = new char[1]; int num6 = 0; int num7 = 0x2f; chArray2[num6] = (char)num7; month = int.Parse(str2.Split(chArray2)[1]); } catch { } try { string str3 = date; char[] chArray3 = new char[1]; int num8 = 0; int num9 = 0x2f; chArray3[num8] = (char)num9; day = int.Parse(str3.Split(chArray3)[2]); } catch { } } catch { } hijri.HijriAdjustment = -1; try { DateTime time = hijri.ToDateTime(year, month, day, 0, 0, 0, 0); string[] strArray = new string[5]; int num10 = 0; strArray[num10] = time.Year.ToString().PadLeft(4, '0'); int num11 = 1; strArray[num11] = "/"; int num12 = 2; strArray[num12] = time.Month.ToString().PadLeft(2, '0'); int num13 = 3; strArray[num13] = "/"; int num14 = 4; strArray[num14] = time.Day.ToString().PadLeft(2, '0'); return(string.Concat(strArray)); } catch { } return(""); }
public static DateTime ToDateTime(this HijriCalendar calendar, int year, IslamicMonths month, int day) { return(calendar.ToDateTime(year, (int)month, day, 0, 0, 0, 0)); }