Пример #1
0
        public static string ToFarsi(this DateTime date, DateConvertType convertDate)
        {
            var pc = new System.Globalization.PersianCalendar();

            return(convertDate == DateConvertType.Short
                ? $"{pc.GetYear(date)}/{pc.GetMonth(date):00}/{pc.GetDayOfMonth(date):00}"
                : $"{DayNamesG[(int) pc.GetDayOfWeek(date)]} {pc.GetDayOfMonth(date)} {MonthNames[pc.GetMonth(date) - 1]} {pc.GetYear(date)}");
        }
Пример #2
0
        public static string ToFarsi(this DateTime date, DateConvertType convertDate, DateAndTimeConvertType dateTime)
        {
            var pc = new System.Globalization.PersianCalendar();

            switch (dateTime)
            {
            case DateAndTimeConvertType.Date:
                if (convertDate == DateConvertType.Short)
                {
                    return
                        ($"{pc.GetYear(date)}/{pc.GetMonth(date):00}/{pc.GetDayOfMonth(date):00}");
                }
                else
                {
                    return
                        ($"{DayNamesG[(int) pc.GetDayOfWeek(date)]} {pc.GetDayOfMonth(date)} {MonthNames[pc.GetMonth(date)]} {pc.GetYear(date)}");
                }


            case DateAndTimeConvertType.Time:
                if (convertDate == DateConvertType.Short)
                {
                    return(date.TimeOfDay.ToString());
                }
                else
                {
                    return(string.Format("ساعت {4}:{5} {6}", date.TimeOfDay.Hours, date.TimeOfDay.Minutes,
                                         date.TimeOfDay.TotalHours > 12 ? "عصر" : "صبح"));
                }

            case DateAndTimeConvertType.Both:
                if (convertDate == DateConvertType.Short)
                {
                    return
                        ($"{pc.GetYear(date)}/{pc.GetMonth(date):00}/{pc.GetDayOfMonth(date):00} {date.TimeOfDay.ToString()}");
                }
                else
                {
                    return
                        ($"{DayNamesG[(int) pc.GetDayOfWeek(date)]} {pc.GetDayOfMonth(date)} {MonthNames[pc.GetMonth(date)]} {pc.GetYear(date)} ساعت {date.TimeOfDay.Hours}:{date.TimeOfDay.Minutes} {(date.TimeOfDay.TotalHours > 12 ? "عصر" : "صبح")}");
                }

            default:
                throw new ArgumentOutOfRangeException(nameof(dateTime), dateTime, null);
            }
        }