/// <summary> /// Returns a value indicating whether this instance is equal to the specified PersianDateTime instance. /// </summary> /// <param name="value">A PersianDateTime instance to compare to this instance.</param> /// <returns>true if the value parameter equals the value of this instance; otherwise, false.</returns> public bool Equals(PersianDateTime value) { if (object.ReferenceEquals(value, null)) { return(false); } return(_dateTime.Equals(value._dateTime)); }
/// <summary> /// Returns a new PersianDateTime that adds the specified number of years to the value of this instance. /// </summary> /// <param name="value">A number of years. The value parameter can be negative or positive.</param> /// <returns>An object whose value is the sum of the date and time represented by this instance and the number of years represented by value.</returns> public PersianDateTime AddYears(int value) { var newYear = Year + value; var daysInNewMonth = PersianDateTime.GetDaysInMonth(newYear, Month); var newDay = daysInNewMonth < Day ? daysInNewMonth : Day; return(new PersianDateTime(Year + value, Month, Day).Add(TimeOfDay)); }
/// <summary> /// Returns a new PersianDateTime that adds the specified number of months to the value of this instance. /// </summary> /// <param name="value">A number of months. The months parameter can be negative or positive.</param> /// <returns>An object whose value is the sum of the date and time represented by this instance and months.</returns> public PersianDateTime AddMonths(int value) { var months = Month + value; var newYear = Year + (months > 0 ? (months - 1) / 12 : months / 12 - 1); var newMonth = months > 0 ? (months - 1) % 12 + 1 : months % 12 + 12; var daysInNewMonth = PersianDateTime.GetDaysInMonth(newYear, newMonth); var newDay = daysInNewMonth < Day ? daysInNewMonth : Day; return(new PersianDateTime(newYear, newMonth, newDay).Add(TimeOfDay)); }
/// <summary> /// تبدیل تاریخ شمسی به میلادی /// </summary> /// <param name="dt">تاریخ شمسی</param> /// <returns> 9/3/2017 3:16:29 PM </returns> public static DateTime ToDateTime(this PersianDateTime dt) { return(dt.ToDateTime()); }
/// <summary> /// تبدیل تاریخ شمسی به شمسی /// </summary> /// <param name="dt">تاریخ شمسی</param> /// <returns> یکشنبه 12 شهریور 1396 </returns> public static string ToPersianDateString(this PersianDateTime dt) { return(dt.ToString("dddd d MMMM yyyy")); }
/// <summary> /// تبدیل تاریخ میلادی به شمسی /// </summary> /// <param name="dt">تاریخ میلادی</param> /// <returns> 1396/06/12 15:16:29 </returns> public static string ToPersianDigitalDateTimeString(this DateTime dt) { var pd = new PersianDateTime(dt); return(pd.ToString("yyyy/MM/d H:mm:ss")); }
/// <summary> /// تبدیل تاریخ میلادی به شمسی /// </summary> /// <param name="dt">تاریخ میلادی</param> /// <returns> 1396/06/12 15:16:29 </returns> public static PersianDateTime ToPersianDateTime(this DateTime dt) { PersianDateTime persiandate = new PersianDateTime(dt); return(persiandate); }
/// <summary> /// تبدیل تاریخ میلادی به شمسی /// </summary> /// <param name="dt">تاریخ میلادی</param> /// <returns> یکشنبه 12 شهریور 1396 </returns> public static string ToPersianDateString(this DateTime dt) { var pd = new PersianDateTime(dt); return(pd.ToString("dddd d MMMM yyyy")); }
/// <summary> /// تبدیل تاریخ شمسی به شمسی /// </summary> /// <param name="dt">تاریخ شمسی</param> /// <returns>1396/06/12</returns> public static string ToPersianDigitalDateString(this PersianDateTime dt) { return(dt.ToString("yyyy/MM/d")); }