public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) { if (value is DateTime) { return(PersianDateTimeConverter.MiladiToShamsi((DateTime)value)); } else if (value is string) { return(PersianDateTime.Parse((string)value)); } else if (value is long) { return(PersianDateTime.FromInt64((long)value)); } throw new ArgumentException("Parameter is not of type PersinaDateTime.", "obj"); }
public static DateTime ShamsiToMiladi(PersianDateTime sh) { int year = sh.Year; int month = sh.Month; int day = sh.Day; ShamsiToMiladi(ref year, ref month, ref day); try { return(new DateTime(year, month, day, sh.Hour, sh.Minute, sh.Second, sh.Millisecond)); } catch (Exception ex) { throw new Exception(string.Format("{0}/{1}/{2} {3}:{4}:{5}", year, month, day, sh.Hour, sh.Minute, sh.Second), ex); } }
public static string ToSQLPersianDateTimeString(PersianDateTime dt) { return("'" + dt.Month.ToString() + "/" + dt.Day.ToString() + "/" + dt.Year.ToString() + " " + dt.Hour.ToString() + ":" + dt.Minute.ToString() + ":" + dt.Second.ToString() + "." + dt.Millisecond.ToString() + "'"); }
public static string ToShamsiStringFull(PersianDateTime dt) { return(dt.ToShortDateTimeString()); }