public string ConvertToIranTimeString(DateTime Date) { //string zoneId = "Iran Standard Time"; //TimeZoneInfo tzi = TimeZoneInfo.FindSystemTimeZoneById(zoneId); //DateTime result = TimeZoneInfo.ConvertTimeFromUtc(Date, tzi); Date = Date.AddMinutes(-150); PersianCalendar pc = new PersianCalendar(); string year = pc.GetYear(Date).ToString(); string Month = pc.GetMonth(Date).ToString(); string Day = pc.GetDayOfMonth(Date).ToString(); string Hour = pc.GetHour(Date).ToString(); string Minute = pc.GetMinute(Date).ToString(); if (Month.Length == 1) { Month = "0" + Month; } if (Day.Length == 1) { Day = "0" + Day; } if (Hour.Length == 1) { Hour = "0" + Hour; } if (Minute.Length == 1) { Minute = "0" + Minute; } return year + "/" + Month + "/" + Day + " " + Hour + ":" + Minute; }
public static SqlString ToPersianDateTime(DateTime dt) { try { string result = ""; if (dt != null) { PersianCalendar objPersianCalendar = new PersianCalendar(); int year = objPersianCalendar.GetYear(dt); int month = objPersianCalendar.GetMonth(dt); int day = objPersianCalendar.GetDayOfMonth(dt); int hour = objPersianCalendar.GetHour(dt); int min = objPersianCalendar.GetMinute(dt); int sec = objPersianCalendar.GetSecond(dt); result = year.ToString().PadLeft(4, '0') + "/" + month.ToString().PadLeft(2, '0') + "/" + day.ToString().PadLeft(2, '0') + " " + hour.ToString().PadLeft(2, '0') + ":" + min.ToString().PadLeft(2, '0') + ":" + sec.ToString().PadLeft(2, '0'); } return new SqlString(result); } catch (Exception e) { return SqlString.Null; } }
public static string GetDate(DateTime date) { DateTime dt = (DateTime)date; PersianCalendar objPersianCalendar = new PersianCalendar(); int year = objPersianCalendar.GetYear(dt); int month = objPersianCalendar.GetMonth(dt); int day = objPersianCalendar.GetDayOfMonth(dt); return string.Concat(year.ToString().PadLeft(4, '0'), month.ToString().PadLeft(2, '0'), day.ToString().PadLeft(2, '0')); }
public string getShamsiDate(DateTime Date) { PersianCalendar pc = new PersianCalendar(); string year = pc.GetYear(Date).ToString(); string Mounth = pc.GetMonth(Date).ToString(); string Day = pc.GetDayOfMonth(Date).ToString(); string shamsiDate = year + "/" + Mounth + "/" + Day; return shamsiDate; }
//public String GetData() //{ // var Lst = context.CharityNews.OrderBy(s => s.SubmitDate).Take(3).ToList(); // JavaScriptSerializer js = new JavaScriptSerializer(); // return js.Serialize(Lst); // } protected string ShamsiDate(Object SubmitDate) { DateTime Date = Convert.ToDateTime(SubmitDate); PersianCalendar pc = new PersianCalendar(); string year = pc.GetYear(Date).ToString(); string Mounth = pc.GetMonth(Date).ToString(); string Day = pc.GetDayOfMonth(Date).ToString(); string shamsiDate=year + "/" + Mounth + "/" + Day; return shamsiDate; }
public void CalendarConversion() { PersianCalendar calendar = new PersianCalendar(); for (int i = 0; i < s_dates.Length; i+= 6) { DateTime date = new DateTime(s_dates[i + 3], s_dates[i + 4], s_dates[i + 5]); Assert.Equal(s_dates[i], calendar.GetYear(date)); Assert.Equal(s_dates[i + 1], calendar.GetMonth(date)); Assert.Equal(s_dates[i + 2], calendar.GetDayOfMonth(date)); DateTime result = calendar.ToDateTime(s_dates[i], s_dates[i + 1], s_dates[i + 2], 0, 0, 0, 0); Assert.Equal(s_dates[i + 3], result.Year); Assert.Equal(s_dates[i + 4], result.Month); Assert.Equal(s_dates[i + 5], result.Day); } }
protected void Page_Load(object sender, EventArgs e) { AccessControl ac = new AccessControl(); if (!ac.getSectionAccess("Charity")) { Response.Redirect("~/Error.aspx?Code=NoAccess"); } DataTable dt = new DataTable(); DataSet ds = new DataSet(); SqlConnection sqlConn = new SqlConnection(ConfigurationManager.ConnectionStrings["ShopConnectionString"].ConnectionString); SqlDataAdapter sda = new SqlDataAdapter("sp_charityNewsInfo", sqlConn); sda.SelectCommand.CommandType = CommandType.StoredProcedure; sda.SelectCommand.Parameters.Add("@NewsId", SqlDbType.Int).Value = Convert.ToInt32(Request.QueryString["NewsId"]); sda.Fill(ds); dt = ds.Tables[0]; if (dt.Rows.Count == 0) //news doesn't exist { Response.Redirect("~/Charity.aspx"); } else //news exists { LabelTitle.Text = dt.Rows[0]["Subject"].ToString(); DateTime NewsDate = Convert.ToDateTime(dt.Rows[0]["SubmitDate"].ToString()); PersianCalendar pc = new PersianCalendar(); string year = pc.GetYear(NewsDate).ToString(); string Mounth = pc.GetMonth(NewsDate).ToString(); string Day = pc.GetDayOfMonth(NewsDate).ToString(); LabelDate.Text = year + "/" + Mounth + "/" + Day; LabelBody.Text = dt.Rows[0]["Body"].ToString(); ImageImage.ImageUrl = "~/images/charity/news/" + Request.QueryString["NewsId"] + ".png"; Page.Title = "Salestan : اخبار خیریه : " + dt.Rows[0]["Subject"].ToString(); HyperLinkShareFacebook.NavigateUrl = "http://www.facebook.com/share.php?u=" + Request.Url.AbsoluteUri + "&t=" + dt.Rows[0]["Subject"].ToString(); HyperLinkShareTwitter.NavigateUrl = "http://twitter.com/home?status=" + dt.Rows[0]["Subject"].ToString() + " " + Request.Url.AbsoluteUri; HyperLinkShareEmail.NavigateUrl = "mailto:?subject=" + dt.Rows[0]["Subject"].ToString() + "&body=" + Request.Url.AbsoluteUri; HyperLinkSharePrint.NavigateUrl = "~/Print.aspx?Mode=CharityNews&ItemId=" + Request.QueryString["NewsId"]; } sda.Dispose(); sqlConn.Close(); }
public static void Log(string log) { PersianCalendar objPersianCalendar = new PersianCalendar(); int year = objPersianCalendar.GetYear(DateTime.Now); int month = objPersianCalendar.GetMonth(DateTime.Now); int day = objPersianCalendar.GetDayOfMonth(DateTime.Now); int hour = objPersianCalendar.GetHour(DateTime.Now); int min = objPersianCalendar.GetMinute(DateTime.Now); StreamWriter objStreamWriter = File.AppendText(HttpContext.Current.Server.MapPath("~/log.txt")); lock (objStreamWriter) { objStreamWriter.WriteLine(string.Concat("Log Date : ", string.Concat(year.ToString(), "/", month.ToString(), "/", day.ToString(), " ", hour.ToString(), ":", min.ToString().PadLeft(2, '0')))); objStreamWriter.WriteLine(log); objStreamWriter.WriteLine("--------------------------------------------"); objStreamWriter.Close(); } }
public static SqlString DATEADDPersian(string datepart, int number, string date) { try { PersianCalendar objPersianCalendar = new PersianCalendar(); DateTime PersianDate = new DateTime(); string result = ""; string[] date_spilt = date.Split('/'); if (datepart == Date_part.YEAR.ToString()) { PersianDate = objPersianCalendar.AddYears(objPersianCalendar.ToDateTime(int.Parse(date_spilt[0]), int.Parse(date_spilt[1]), int.Parse(date_spilt[2]), 0, 0, 0, 0), number); } else if (datepart == Date_part.DAY.ToString()) { PersianDate = objPersianCalendar.AddDays(objPersianCalendar.ToDateTime(int.Parse(date_spilt[0]), int.Parse(date_spilt[1]), int.Parse(date_spilt[2]), 0, 0, 0, 0), number); } result = string.Format("{0}/{1}/{2}", objPersianCalendar.GetYear(PersianDate).ToString().PadLeft(4, '0'), objPersianCalendar.GetMonth(PersianDate).ToString().PadLeft(2, '0'), objPersianCalendar.GetDayOfMonth(PersianDate).ToString().PadLeft(2, '0')); return new SqlString(result); } catch (Exception e) { return SqlString.Null; } }
public string miladi2shamsi(DateTime _date) { //کد مربوط به تاریخ به صورت ماه و روز PersianCalendar pc = new PersianCalendar(); StringBuilder sb = new StringBuilder(); sb.Append(pc.GetYear(_date).ToString("0000")); sb.Append("/"); sb.Append(pc.GetMonth(_date).ToString("00")); sb.Append("/"); sb.Append(pc.GetDayOfMonth(_date).ToString("00")); sb.Append(" امروز :"); //sb.Append(pc.GetDayOfWeek(_date).ToString()); string s = pc.GetDayOfWeek(_date).ToString(); switch (s.ToUpper()) { case "SATURDAY": sb.Append(" شنبه"); break; case "SUNDAY": sb.Append(" يكشنبه"); break; case "MONDAY": sb.Append(" دوشنبه"); break; case "TUESDAY": sb.Append(" سه شنبه"); break; case "WEDNESDAY": sb.Append(" چهار شنبه"); break; case "THURSDAY": sb.Append(" بنچ شنبه"); break; case "FRIDAY": sb.Append(" جمعه"); break; } return(sb.ToString()); }
public static string MeladiToShamsi(string strMeladi) { DateTime d = DateTime.Parse(strMeladi); PersianCalendar pc = new PersianCalendar(); return(string.Format("{0}/{1}/{2}", pc.GetYear(d), (pc.GetMonth(d).ToString().Length < 2 ? "0" + pc.GetMonth(d) : pc.GetMonth(d).ToString()), (pc.GetDayOfMonth(d).ToString().Length < 2 ? "0" + pc.GetDayOfMonth(d) : pc.GetDayOfMonth(d).ToString()))); }
public void UpdateTuitionPayment(PaymentDTO pay) { PersianCalendar pc = new PersianCalendar(); var persianDate = pc.GetYear(DateTime.Now).ToString() + '/' + pc.GetMonth(DateTime.Now).ToString() + '/' + pc.GetDayOfMonth(DateTime.Now).ToString(); try { SqlCommand cmd1 = new SqlCommand(); cmd1.Connection = conn; cmd1.CommandType = CommandType.StoredProcedure; cmd1.CommandText = "dbo.webmeli_insert_mali_meli"; cmd1.Parameters.AddWithValue("@idorder", pay.OrderId); cmd1.Parameters.AddWithValue("@stcode", pay.stcode); cmd1.Parameters.AddWithValue("@nopaygeri", pay.TraceNumber.ToString() + "IAUEC"); cmd1.Parameters.AddWithValue("@oksabt", 0); cmd1.Parameters.AddWithValue("@datesabt", pay.PayDate); cmd1.Parameters.AddWithValue("@resultdate", persianDate); cmd1.Parameters.AddWithValue("@resulttime", DateTime.Now.ToString("HH:mm")); cmd1.Parameters.AddWithValue("@amount", pay.Amount); cmd1.Parameters.AddWithValue("@termjary", pay.tterm); conn.Open(); cmd1.ExecuteNonQuery(); conn.Close(); } catch (Exception) { throw; } }
public static string ToShamsi(this DateTime value) { PersianCalendar p = new PersianCalendar(); return(p.GetYear(value) + "/" + p.GetMonth(value).ToString("00") + "/" + p.GetDayOfMonth(value).ToString("00")); }
protected void grid_show_cutted_and_remain_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "delete_cutted") { rowIndex = int.Parse(e.CommandArgument.ToString()); ViewState["delete_id"] = (int)grid_show_cutted_and_remain.DataKeys[rowIndex]["ID"]; pnl_delete_warning.Visible = true; } if (e.CommandName == "decrease_value") { PersianCalendar pc = new PersianCalendar(); string PDate = pc.GetYear(DateTime.Now) + "/" + pc.GetMonth(DateTime.Now) + "/" + pc.GetDayOfMonth(DateTime.Now); string timeAndDate = DateTime.Now.ToString("h:mm") + " - " + PDate; rowIndex = int.Parse(e.CommandArgument.ToString()); index = Convert.ToInt32(e.CommandArgument); ViewState["decrease_id"] = (int)grid_show_cutted_and_remain.DataKeys[rowIndex]["ID"]; GridViewRow row = grid_show_cutted_and_remain.Rows[index]; TextBox txt_changevalue = row.Cells[0].FindControl("txt_change_cutted") as TextBox; if (!string.IsNullOrEmpty(txt_changevalue.Text)) { changevalue = Convert.ToInt32(txt_changevalue.Text); con.Open(); SqlCommand checkcutted = new SqlCommand( "SELECT cutted as cutted from cutted_and_remain WHERE(ID = " + ViewState["decrease_id"] + ") ", con); cutted_value = Convert.ToInt32(checkcutted.ExecuteScalar()); } if (changevalue > cutted_value || string.IsNullOrEmpty(txt_changevalue.Text) || changevalue == 0) { txt_changevalue.BorderColor = Color.Red; } else { SqlCommand updatetable = new SqlCommand("UPDATE [dbo].[cutted_and_remain] " + "SET [cutted] = [cutted] - " + changevalue + " " + ",[record4] = [record3] " + ",[td4] = [td3]" + ",[record3] = [record2] " + ",[td3] = [td2]" + ",[record2] = [record1] " + ",[td2] = [td1]" + ",[record1] = '" + txt_changevalue.Text + "' + '-' " + ",[td1] = '" + timeAndDate + "' " + "WHERE(ID = " + ViewState["decrease_id"] + ")", con); updatetable.ExecuteNonQuery(); SqlCommand update2 = new SqlCommand("UPDATE [flower_depot].[dbo].[cutted_and_remain] " + "SET [total] = [cutted] + [falleh] + [service] " + "WHERE (ID = " + ViewState["decrease_id"] + ") ", con); update2.ExecuteNonQuery(); con.Close(); grid_show_cutted_and_remain.DataBind(); txt_changevalue.Text = ""; } } if (e.CommandName == "increase_value") { PersianCalendar pc = new PersianCalendar(); string PDate = pc.GetYear(DateTime.Now) + "/" + pc.GetMonth(DateTime.Now) + "/" + pc.GetDayOfMonth(DateTime.Now); string timeAndDate = DateTime.Now.ToString("h:mm") + " - " + PDate; rowIndex = int.Parse(e.CommandArgument.ToString()); index = Convert.ToInt32(e.CommandArgument); ViewState["increase_id"] = (int)grid_show_cutted_and_remain.DataKeys[rowIndex]["ID"]; GridViewRow row1 = grid_show_cutted_and_remain.Rows[index]; TextBox txt_changevalue1 = row1.Cells[0].FindControl("txt_change_cutted") as TextBox; if (!string.IsNullOrEmpty(txt_changevalue1.Text) || changevalue != 0) { changevalue1 = Convert.ToInt32(txt_changevalue1.Text); } if (string.IsNullOrEmpty(txt_changevalue1.Text) || Convert.ToInt32(txt_changevalue1.Text) == 0) { txt_changevalue1.BorderColor = Color.Red; } else { con.Open(); SqlCommand update = new SqlCommand("UPDATE [flower_depot].[dbo].[cutted_and_remain] " + "SET [cutted] = [cutted]+ " + changevalue1 + " " + ",[record4] = [record3] " + ",[td4] = [td3]" + ",[record3] = [record2] " + ",[td3] = [td2]" + ",[record2] = [record1] " + ",[td2] = [td1]" + ",[record1] = '" + txt_changevalue1.Text + "' + '+' " + ",[td1] = '" + timeAndDate + "' " + "WHERE (ID = " + ViewState["increase_id"] + ") ", con); update.ExecuteNonQuery(); SqlCommand update2 = new SqlCommand("UPDATE [flower_depot].[dbo].[cutted_and_remain] " + "SET [total] = [cutted] + [falleh] + [service] " + "WHERE (ID = " + ViewState["increase_id"] + ") ", con); update2.ExecuteNonQuery(); con.Close(); grid_show_cutted_and_remain.DataBind(); txt_changevalue1.Text = ""; } } }
public static string GetPersianDateAndTimeText(DateTime dateTime) { try { var persianCalendar = new PersianCalendar(); dateTime = dateTime.ToLocalTime(); return($"{Convert.ToDateTime(persianCalendar.GetYear(dateTime) + "/" + persianCalendar.GetMonth(dateTime) + "/" + persianCalendar.GetDayOfMonth(dateTime)):yyyy/MM/dd}|{Convert.ToDateTime(dateTime.TimeOfDay.Hours + ":" + dateTime.TimeOfDay.Minutes + ":" + dateTime.TimeOfDay.Seconds):HH:mm:ss}"); } catch (Exception) { return(String.Empty); } }
public static string GetGregorianToPersianDateInverse(DateTime dateTime) { try { var persianCalendar = new PersianCalendar(); dateTime = dateTime.ToLocalTime(); return($"{GetPersianDayOfWeek(persianCalendar.GetDayOfWeek(dateTime))} - {persianCalendar.GetDayOfMonth(dateTime):00} {GetPersianMonth(persianCalendar.GetMonth(dateTime))} {persianCalendar.GetYear(dateTime)}"); } catch (Exception) { return(String.Empty); } }
public static string GetToday() { PersianCalendar pc = new PersianCalendar(); return(pc.GetYear(DateTime.Now).ToString("0000") + "/" + pc.GetMonth(DateTime.Now).ToString("00") + "/" + pc.GetDayOfMonth(DateTime.Now).ToString("00")); }
public void SetDateTimeNow(MaskedTextBox objMTB) { PersianCalendar objPC = new PersianCalendar(); objMTB.Text = objPC.GetYear(DateTime.Now).ToString("0000") + objPC.GetMonth(DateTime.Now).ToString("00") + objPC.GetDayOfMonth(DateTime.Now).ToString("00"); }
public static int GetPersianDay(DateTime dateTime) { PersianCalendar Calendar = new PersianCalendar(); return(Calendar.GetDayOfMonth(dateTime)); }
public string DateAndTimeBackup(DateTime _DateAndTimeBackup) { DateTime dateTime; if (IsConnectedToInternet()) { XmlDocument document = new XmlDocument(); document.Load("http://nist.time.gov/actualtime.cgi?lzbc=siqm9b"); if (document.DocumentElement != null) { var timeAttribute = document.DocumentElement.GetAttributeNode("time"); if (timeAttribute != null && timeAttribute.Value != null) { string time = timeAttribute.Value; long milliseconds = Convert.ToInt64(time) / 1000; dateTime = new DateTime(1970, 1, 1).AddMilliseconds(milliseconds).ToLocalTime(); return(dateTime.ToString("yyyy-mm-dd HH-mm-ss")); } } } PersianCalendar pc = new PersianCalendar(); string date = pc.GetYear(DateTime.Now) + "/" + pc.GetMonth(DateTime.Now) + "/" + pc.GetDayOfMonth(DateTime.Now) + " " + pc.GetHour(DateTime.Now) + "-" + pc.GetMinute(DateTime.Now) + "-" + pc.GetSecond(DateTime.Now); return(date.ToString()); //var timeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById("Iran Standard Time"); //dateTime = TimeZoneInfo.ConvertTime(DateTime.Now, timeZoneInfo); //return dateTime.ToString("yyyy-mm-dd HH-mm-ss"); }
protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { if ((((string)Session["level"] != "programer") || (Convert.ToInt32(Session["userid"]) != 15)) && (((string)Session["level"] != "mng_product") || (Convert.ToInt32(Session["userid"]) != 16)) && (((string)Session["level"] != "Bana") || (Convert.ToInt32(Session["userid"]) != 34))) { Response.Redirect("../login.aspx"); Session.Clear(); } } System.Globalization.PersianCalendar pc = new System.Globalization.PersianCalendar(); DateTime miladi; DateTime datetimeformat = DateTime.Now; PersianCalendar p = new PersianCalendar(); miladi = datetimeformat; datetimeformat = p.AddDays(miladi, -1); date_end = p.GetYear(datetimeformat).ToString("0000") + '/' + p.GetMonth(datetimeformat).ToString("00") + '/' + p.GetDayOfMonth(datetimeformat).ToString("00"); if (!Page.IsPostBack) { lbldate_e.Text = date_end; lbldate_s.Text = date_end; year = date_end.Substring(0, 4); dryearstart.SelectedValue = year; mounth = date_end.Substring(5, 2); drmounthstart.SelectedValue = mounth; day = date_end.Substring(8, 2); drdaystart.SelectedValue = day; year = date_end.Substring(0, 4); dryear.SelectedValue = year; mounth = date_end.Substring(5, 2); drmounth.SelectedValue = mounth; day = date_end.Substring(8, 2); drday.SelectedValue = day; } }
public static void Main() { PersianCalendar pc = new PersianCalendar(); DateTime thisDate = DateTime.Now; // Display the current date using the Gregorian and Persian calendars. Console.WriteLine("Today in the Gregorian Calendar: {0:dddd}, {0}", thisDate); Console.WriteLine("Today in the Persian Calendar: {0}, {1}/{2}/{3} {4}:{5}:{6}\n", pc.GetDayOfWeek(thisDate), pc.GetMonth(thisDate), pc.GetDayOfMonth(thisDate), pc.GetYear(thisDate), pc.GetHour(thisDate), pc.GetMinute(thisDate), pc.GetSecond(thisDate)); // Create a date using the Gregorian calendar. thisDate = new DateTime(2013, 5, 28, 10, 35, 0); Console.WriteLine("Gregorian Calendar: {0:D} ", thisDate); Console.WriteLine("Persian Calendar: {0}, {1}/{2}/{3} {4}:{5}:{6}\n", pc.GetDayOfWeek(thisDate), pc.GetMonth(thisDate), pc.GetDayOfMonth(thisDate), pc.GetYear(thisDate), pc.GetHour(thisDate), pc.GetMinute(thisDate), pc.GetSecond(thisDate)); // Create a date using the Persian calendar. thisDate = pc.ToDateTime(1395, 4, 22, 12, 30, 0, 0); Console.WriteLine("Gregorian Calendar: {0:D} ", thisDate); Console.WriteLine("Persian Calendar: {0}, {1}/{2}/{3} {4}:{5}:{6}\n", pc.GetDayOfWeek(thisDate), pc.GetMonth(thisDate), pc.GetDayOfMonth(thisDate), pc.GetYear(thisDate), pc.GetHour(thisDate), pc.GetMinute(thisDate), pc.GetSecond(thisDate)); // Show the Persian Calendar date range. Console.WriteLine("Minimum Persian Calendar date (Gregorian Calendar): {0:D} ", pc.MinSupportedDateTime); Console.WriteLine("Minimum Persian Calendar date (Persian Calendar): " + "{0}, {1}/{2}/{3} {4}:{5}:{6}\n", pc.GetDayOfWeek(pc.MinSupportedDateTime), pc.GetMonth(pc.MinSupportedDateTime), pc.GetDayOfMonth(pc.MinSupportedDateTime), pc.GetYear(pc.MinSupportedDateTime), pc.GetHour(pc.MinSupportedDateTime), pc.GetMinute(pc.MinSupportedDateTime), pc.GetSecond(pc.MinSupportedDateTime)); Console.WriteLine("Maximum Persian Calendar date (Gregorian Calendar): {0:D} ", pc.MaxSupportedDateTime); Console.WriteLine("Maximum Persian Calendar date (Persian Calendar): " + "{0}, {1}/{2}/{3} {4}:{5}:{6}\n", pc.GetDayOfWeek(pc.MaxSupportedDateTime), pc.GetMonth(pc.MaxSupportedDateTime), pc.GetDayOfMonth(pc.MaxSupportedDateTime), pc.GetYear(pc.MaxSupportedDateTime), pc.GetHour(pc.MinSupportedDateTime), pc.GetMinute(pc.MaxSupportedDateTime), pc.GetSecond(pc.MaxSupportedDateTime)); }
public NowDateTime GetNow() //public DateTime GetNow() { NowDateTime ndt = new NowDateTime(); ndt.Now = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); PersianCalendar pc = new PersianCalendar(); DateTime dtN = DateTime.Now; ndt.NowDateFa = pc.GetYear(dtN).ToString() + "/" + pc.GetMonth(dtN).ToString().PadLeft(2, '0') + "/" + pc.GetDayOfMonth(dtN).ToString().PadLeft(2, '0'); ndt.NowTime = dtN.ToString("HH:mm:ss"); ndt.NowDateTimeFa = ndt.NowDateFa + " " + ndt.NowTime; // --- MessageCount oldmsc = (MessageCount)MemoryCacher.GetValue("MessageCount"); if ((oldmsc == null) || (oldmsc.InsDateFa != ndt.NowDateFa)) { MessageCount msc = MessageUtility.GetSmsCountByDate(ndt.NowDateFa); ndt.MsgCount = msc; MemoryCacher.Add("MessageCount", msc, DateTimeOffset.Now.AddSeconds(5)); } else { ndt.MsgCount = oldmsc; } // --- return(ndt); }
private void dateFindLostForm_Load(object sender, EventArgs e) { PersianCalendar pc = new PersianCalendar(); var n = DateTime.Now; textBox1.Text = pc.GetYear(n).ToString() + "/" + pc.GetMonth(n).ToString() + "/" + pc.GetDayOfMonth(n).ToString(); var emp = StartForm.EmpDb.Employees.Select(lastname => lastname.LastName + " " + lastname.FirstName).ToList(); foreach (var item in emp) { comboBox1.Items.Add(item); } }
public NowDateTime GetNowU([FromBody] NowDateTime ndt) //public DateTime GetNow() { try { User user = new User(); var identity = (ClaimsIdentity)User.Identity; IEnumerable <Claim> claims = identity.Claims; user.AppName = claims.FirstOrDefault(x => x.Type == "AppName").Value.ToString(); user.USERID = Convert.ToInt32(claims.FirstOrDefault(x => x.Type == "UserId").Value.ToString()); user.AREACODE = Convert.ToInt32(claims.FirstOrDefault(x => x.Type == "AreaCode").Value.ToString()); user.FNAME = claims.FirstOrDefault(x => x.Type == "FName").Value.ToString(); user.LNAME = claims.FirstOrDefault(x => x.Type == "LName").Value.ToString(); user.ClientVersion = claims.FirstOrDefault(x => x.Type == "ClientVersion").Value.ToString(); //--- // String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss"; //String mDateTime = DateUtils.formatDateTimeFromDate(DATE_FORMAT, Calendar.getInstance().getTime()); ndt.Now = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); PersianCalendar pc = new PersianCalendar(); DateTime dtN = DateTime.Now; ndt.NowDateFa = pc.GetYear(dtN).ToString() + "/" + pc.GetMonth(dtN).ToString().PadLeft(2, '0') + "/" + pc.GetDayOfMonth(dtN).ToString().PadLeft(2, '0'); ndt.NowTime = dtN.ToString("HH:mm:ss"); ndt.NowDateTimeFa = ndt.NowDateFa + " " + ndt.NowTime; // --- //MessageCount oldmsc = (MessageCount)MemoryCacher.GetValue("MessageCount"); //if ((oldmsc == null) || (oldmsc.InsDateFa != ndt.NowDateFa)) //{ // MessageCount msc = MessageUtility.GetSmsCountByDate(ndt.NowDateFa); // ndt.MsgCount = msc; // if (oldmsc != null) // MemoryCacher.Delete("MessageCount"); // MemoryCacher.Add("MessageCount", msc, DateTimeOffset.Now.AddSeconds(30)); //} //else // ndt.MsgCount = oldmsc; // --- //LogManager.SetCommonLog(String.Format(@"GetNowU time:{0} From:{1} by:{2} UserId:{3}", ndt.NowDateFa, user.AppName, ndt.QCUsertSrl.ToString(), user.USERID)); GeneralUtility.UpdateUserData(user, ndt, 1); } catch (Exception e) { DBHelper.LogFile(e); } return(ndt); //ToShortDateString()+" " + DateTime.Now.ToShortTimeString(); }
public static string ConvertEnglishToPersianDate(DateTime?dt) { if (dt == null) { return(""); } PersianCalendar Pdate = new PersianCalendar(); return(Pdate.GetYear(dt.Value).ToString("0000") + "/" + Pdate.GetMonth(dt.Value).ToString("00") + "/" + Pdate.GetDayOfMonth(dt.Value).ToString("00")); }
public static string ToShamsiDateTime(this DateTime value) { PersianCalendar pc = new PersianCalendar(); return(pc.GetYear(value).ToString() + "/" + pc.GetMonth(value) + "/" + pc.GetDayOfMonth(value) + " " + pc.GetHour(value).ToString() + ":" + pc.GetMinute(value).ToString()); }
public static string GetPersianDateText(DateTime dateTime) { try { var persianCalendar = new PersianCalendar(); dateTime = dateTime.ToLocalTime(); return($"{Convert.ToDateTime(persianCalendar.GetYear(dateTime) + "/" + persianCalendar.GetMonth(dateTime) + "/" + persianCalendar.GetDayOfMonth(dateTime)):yyyy/MM/dd}"); } catch (Exception) { return(String.Empty); } }
public static int GetPersianDayOfMonth(DateTime date) { PersianCalendar pc = new PersianCalendar(); return(pc.GetDayOfMonth(date)); }
public QuestionsListView() { InitializeComponent(); this.DataContext = this; main = this; strDate = pc.GetYear(DateTime.Now).ToString("0000") + "/" + pc.GetMonth(DateTime.Now).ToString("00") + "/" + pc.GetDayOfMonth(DateTime.Now).ToString("00"); BorderColor = AppVariable.GetBrush(MainWindow.main.BorderBrush.ToString()); }
public string ConvertDateToPersian(DateTime dt) { DateTime d = dt; PersianCalendar pc = new PersianCalendar(); return(string.Format("{0}/{1}/{2} {3}:{4}:{5}.{6}", pc.GetYear(d), pc.GetMonth(d), pc.GetDayOfMonth(d), pc.GetHour(d), pc.GetMinute(d), pc.GetSecond(d), pc.GetMilliseconds(d))); }
private void Form1_Load(object sender, EventArgs e) { y = persian.GetYear(DateTime.Now); m = persian.GetMonth(DateTime.Now); d = persian.GetDayOfMonth(DateTime.Now); s = Convert.ToInt32((persian.GetDayOfWeek(DateTime.Now))); button5.Text = "امروز:" + string.Format(" {3} {2} {1} {0:d4}", y, pm[m - 1], d, wd[s + 1]); }
public static bool HolidayTest(DateTime inDateTime) { PersianCalendar p = new PersianCalendar(); //var miladi = p..(yeear, moonth, daay, 0, 0, 0, 0); //var week = persianCalendar.GetDayOfWeek(miladi); bool b; try { var url = "http://www.time.ir/fa/event/list/0/" + p.GetYear(inDateTime) + "/" + p.GetMonth(inDateTime) + "/" + p.GetDayOfMonth(inDateTime); var web = new HtmlWeb(); var doc = web.Load(url); b = doc.Text.Contains("eventHoliday"); } catch { b = false; } bool c = Convert.ToString(p.GetDayOfWeek(inDateTime)).Contains("Friday"); if (b == true || c == true) { return(true); } else { return(false); } }
private void FillGridDays(int year, int month) { dgv_Calenar.Rows.Clear(); _currentYear = year; _currentMonth = month; var calendar = new PersianCalendar(); lbl_CurrentCalendarDate.Text = new DateTime(year, month, 1, calendar).ToString("MMM yyyy"); var todayMonthDay = calendar.GetDayOfMonth(DateTime.Now); var todayYear = calendar.GetYear(DateTime.Now); var todayMonth = calendar.GetMonth(DateTime.Now); var lastMonthDays = month == 1 ? calendar.GetDaysInMonth(year - 1, 12) : calendar.GetDaysInMonth(year, month - 1); var currentMonthDays = calendar.GetDaysInMonth(year, month); var fristDayOfWeek = calendar.GetDayOfWeek(new DateTime(year, month, 1, calendar)); var fristDayOfWeekIndex = 0; if (fristDayOfWeek == DayOfWeek.Saturday) { fristDayOfWeekIndex = 0; } else { fristDayOfWeekIndex = (int)fristDayOfWeek + 1; } var rowIndex = 0; var cellIndex = 0; dgv_Calenar.Rows.Add(1); var lastMonthStartDate = lastMonthDays - fristDayOfWeekIndex + 1; for (var dayIndex = lastMonthStartDate; dayIndex <= lastMonthDays; dayIndex++) { dgv_Calenar.Rows[rowIndex].Cells[cellIndex].Tag = new DateTime(month == 1 ? year - 1 : year, month == 1 ? 12 : month - 1, dayIndex, calendar); dgv_Calenar.Rows[rowIndex].Cells[cellIndex].Value = dayIndex; dgv_Calenar.Rows[rowIndex].Cells[cellIndex++].Style.ForeColor = Color.SlateGray; } var SelectedDateExists = false; for (var dayIndex = 1; dayIndex <= currentMonthDays; dayIndex++) { dgv_Calenar.Rows[rowIndex].Cells[cellIndex].Value = dayIndex; dgv_Calenar.Rows[rowIndex].Cells[cellIndex].Tag = new DateTime(year, month, dayIndex, calendar); var currentCell = new DateTime(year, month, dayIndex, calendar); if (dayIndex == todayMonthDay && month == todayMonth && year == todayYear) { dgv_Calenar.Rows[rowIndex].Cells[cellIndex].Style.BackColor = Color.Gray; dgv_Calenar.Rows[rowIndex].Cells[cellIndex].Style.ForeColor = Color.White; } if (currentCell.Year == SelectedDate.Year && currentCell.Month == SelectedDate.Month && currentCell.Day == SelectedDate.Day) { OnSelectedDateChanged?.Invoke(this, new EventArgs()); dgv_Calenar.Rows[rowIndex].Cells[cellIndex].Selected = SelectedDateExists = true; } cellIndex++; { if (cellIndex > 6) { cellIndex = 0; rowIndex++; dgv_Calenar.Rows.Add(1); } } } var nextMonthDay = 1; if (cellIndex > 0) { for (var dayIndex = cellIndex; dayIndex <= 6; dayIndex++) { dgv_Calenar.Rows[rowIndex].Cells[cellIndex].Tag = new DateTime(month == 12 ? year + 1 : year, month == 12 ? 1 : month + 1, dayIndex, calendar); dgv_Calenar.Rows[rowIndex].Cells[cellIndex].Value = nextMonthDay++; dgv_Calenar.Rows[rowIndex].Cells[cellIndex++].Style.ForeColor = Color.SlateGray; } } foreach (var row in dgv_Calenar.Rows.OfType <DataGridViewRow>()) { row.Height = 20; } if (!SelectedDateExists) { dgv_Calenar.CurrentCell = null; } }
public static string ConvertToPersian(string date) { if (date != null && date != "") { DateTime d = DateTime.Parse(date); PersianCalendar pc = new PersianCalendar(); return(string.Format("{0}/{1}/{2} {3}:{4}:{5}", pc.GetYear(d), pc.GetMonth(d), pc.GetDayOfMonth(d), pc.GetHour(d), pc.GetMinute(d), pc.GetSecond(d))); } else { return(""); } }
public static string GetPersianDetial(this DateTime dt) { PersianCalendar _persian = new PersianCalendar(); int day = _persian.GetDayOfMonth(dt); int Month = _persian.GetMonth(dt); int year = _persian.GetYear(dt); string str = " امروز "; DayOfWeek d = _persian.GetDayOfWeek(dt); switch (d) { case DayOfWeek.Friday: { str += " جمعه "; break; } case DayOfWeek.Monday: { str += " دوشنبه "; break; } case DayOfWeek.Saturday: { str += " شنبه "; break; } case DayOfWeek.Sunday: { str += " یکشنبه "; break; } case DayOfWeek.Thursday: { str += " پنج شنبه "; break; } case DayOfWeek.Tuesday: { str += " سه شنبه "; break; } case DayOfWeek.Wednesday: { str += " چهار شنبه "; break; } } str += day; switch (Month) { case 1: { str += " فروردین ماه ";; break; } case 2: { str += " اردیبهشت ماه ";; break; } case 3: { str += " خرداد ماه ";; break; } case 4: { str += " تیر ماه ";; break; } case 5: { str += " مرداد ماه ";; break; } case 6: { str += " شهریور ماه ";; break; } case 7: { str += " مهر ماه ";; break; } case 8: { str += " آبان ماه ";; break; } case 9: { str += " آذر ماه ";; break; } case 10: { str += " دی ماه ";; break; } case 11: { str += " بهمن ماه ";; break; } case 12: { str += " اسفند ماه ";; break; } } str += " سال " + year; return(str); }
private void btnBackup_Click(object sender, EventArgs e) { strShamsi = PC.GetYear(DateTime.Now).ToString("0000") + "_" + PC.GetMonth(DateTime.Now).ToString("00") + "_" + PC.GetDayOfMonth(DateTime.Now).ToString("00"); string strFileName = string.Empty; saveFileDialog1.DefaultExt = "BAK"; saveFileDialog1.FileName = "BackupFile" + strShamsi; saveFileDialog1.Filter = @"SQL Backup files (*.BAK) |*.BAK|All files(*.*) |*.*"; saveFileDialog1.FilterIndex = 1; saveFileDialog1.OverwritePrompt = true; saveFileDialog1.Title = "Backup SQL File"; if (saveFileDialog1.ShowDialog() == DialogResult.OK) { try { isWorking = true; btnBackup.Enabled = false; splashScreenManager1.ShowWaitForm(); strFileName = saveFileDialog1.FileName; txtPath.Text = strFileName; Cursor.Current = Cursors.WaitCursor; //Connect to DB SqlConnection connect; string con = Properties.Settings.Default.ClassSRMConnectionString; connect = new SqlConnection(con); connect.Open(); //Execute SqlCommand command; command = new SqlCommand(@"backup database ClassSRM to disk ='" + strFileName + "'", connect); command.ExecuteNonQuery(); connect.Close(); splashScreenManager1.CloseWaitForm(); XtraMessageBox.Show("پشتیبان گیری با موفقیت انجام شد", "پشتیبان گیری", MessageBoxButtons.OK, MessageBoxIcon.Information); btnBackup.Enabled = true; isWorking = false; if (isUpdate) { isUpdate = false; Close(); } } catch (Exception) { splashScreenManager1.CloseWaitForm(); XtraMessageBox.Show("لطفا درایو دیگری بجز درایو C انتخاب کنید.", "خطا", MessageBoxButtons.OK, MessageBoxIcon.Error); btnBackup.Enabled = true; isWorking = false; } } }
public static string ToPersianDateTime(object date) { string result = null; if (date != null) { DateTime dt = (DateTime)date; PersianCalendar objPersianCalendar = new PersianCalendar(); int year = objPersianCalendar.GetYear(dt); int month = objPersianCalendar.GetMonth(dt); int day = objPersianCalendar.GetDayOfMonth(dt); int hour = objPersianCalendar.GetHour(dt); int min = objPersianCalendar.GetMinute(dt); int sec = objPersianCalendar.GetSecond(dt); result = string.Concat(year.ToString().PadLeft(4, '0'), DateTimeFormatInfo.CurrentInfo.DateSeparator, month.ToString().PadLeft(2, '0'), DateTimeFormatInfo.CurrentInfo.DateSeparator, day.ToString().PadLeft(2, '0'), " ", hour.ToString().PadLeft(2, '0'), DateTimeFormatInfo.CurrentInfo.TimeSeparator, min.ToString().PadLeft(2, '0')); } return result; }
public static string MiladiToShamsi(this DateTime miladiDate) { string result; if (_persianDates.TryGetValue(miladiDate.Date, out result) == false) { PersianCalendar persianCalendar = new PersianCalendar(); result = $"{persianCalendar.GetYear(miladiDate)}/{persianCalendar.GetMonth(miladiDate).FixNumber(2)}/{persianCalendar.GetDayOfMonth(miladiDate).FixNumber(2)}"; _persianDates[miladiDate.Date] = result; } return(result); }
public static string ToShamsiFull(this DateTime dtTime) { PersianCalendar perCal = new PersianCalendar(); var year = perCal.GetYear(dtTime).ToString(); var month = perCal.GetMonth(dtTime).ToString(); var day = perCal.GetDayOfMonth(dtTime).ToString(); var dayofweek = perCal.GetDayOfWeek(dtTime).ToString(); var hours = perCal.GetHour(dtTime).ToString(); var minute = perCal.GetMinute(dtTime).ToString(); var second = perCal.GetSecond(dtTime).ToString(); switch (Int32.Parse(month)) { case 1: month = "فروردین"; break; case 2: month = "اردیبهشت"; break; case 3: month = "خرداد"; break; case 4: month = "تیر"; break; case 5: month = "مرداد"; break; case 6: month = "شهریور"; break; case 7: month = "مهر"; break; case 8: month = "ابان"; break; case 9: month = "آذر"; break; case 10: month = "دی"; break; case 11: month = "بهمن"; break; case 12: month = "اسفند"; break; default: month = "None"; break; } switch (dayofweek) { case "Saturday": dayofweek = "شنبه"; break; case "Sunday": dayofweek = "یکشنبه"; break; case "Monday": dayofweek = "دوشنبه"; break; case "Tuesday": dayofweek = "سه شنبه"; break; case "Wednesday": dayofweek = "چهار شنبه"; break; case "Thursday": dayofweek = "پنج شنبه"; break; case "Friday": dayofweek = "جمعه"; break; default: dayofweek = "None"; break; } var strDate = dayofweek + " " + day + ' ' + month + ' ' + year + " ساعت " + hours + ":" + minute + ":" + second; return(strDate); }
public static string ToPersianDateTime(object date) { string result = null; if (date != null) { DateTime dt = (DateTime)date; PersianCalendar objPersianCalendar = new PersianCalendar(); int year = objPersianCalendar.GetYear(dt); int month = objPersianCalendar.GetMonth(dt); int day = objPersianCalendar.GetDayOfMonth(dt); int hour = objPersianCalendar.GetHour(dt); int minute = objPersianCalendar.GetMinute(dt); result = string.Format("{0}/{1}/{2} {3}:{4}", year, month, day, hour, minute); } return result; }