Ejemplo n.º 1
0
 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");
 }
Ejemplo n.º 2
0
        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);
            }
        }
Ejemplo n.º 3
0
 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() + "'");
 }
Ejemplo n.º 4
0
 public static string ToShamsiStringFull(PersianDateTime dt)
 {
     return(dt.ToShortDateTimeString());
 }