示例#1
0
        public static string FormatPersian(int?persianDate, string format = "yy/m/d", bool persianDigits = true)
        {
            if (!persianDate.HasValue)
            {
                return(null);
            }

            int date = persianDate.Value;

            int year  = date / 10000;
            int month = date / 100 % 100;
            int day   = date % 100;

            var strDate = new StringBuilder(format);

            strDate.Replace("ddd", PersianWeekday(PersianToGregorian(year, month, day)));
            strDate.Replace("dd", day.ToString("00"));
            strDate.Replace("d", day.ToString());
            strDate.Replace("mmm", PersianMonth(month));
            strDate.Replace("mm", month.ToString("00"));
            strDate.Replace("m", month.ToString());
            strDate.Replace("yyyy", year.ToString());
            strDate.Replace("yy", (year % 100).ToString());
            return(persianDigits ? NumeralConvert.PersianDigits(strDate) : strDate.ToString());
        }
示例#2
0
文件: Util.cs 项目: pellk/Util
        public static string UrlSlug(this string phrase)
        {
            string str = NumeralConvert.LatinDigits(phrase.ToLowerInvariant());

            str = Regex.Replace(str, @"[^a-z0-9آابپتثجچحخدذرزژسشصضطظعغفقکگلمنوهیكيئؤأإءڕڤۆێھە\s-]", "", RegexOptions.IgnoreCase);
            str = Regex.Replace(str.Trim(), @"\s+", "-");
            return(str);
        }
示例#3
0
        public static string GregorianToPersian(DateTime gregorianDate, bool twoDigitYear = true, bool monthName = false, bool persianDigits = true)
        {
            int year  = calendar.GetYear(gregorianDate);
            int month = calendar.GetMonth(gregorianDate);
            int day   = calendar.GetDayOfMonth(gregorianDate);

            string date = monthName
                ? $"{day} {PersianMonth(month)} {(twoDigitYear ? year % 100 : year)}"
                : $"{(twoDigitYear ? year % 100 : year)}/{month}/{day}";

            return(persianDigits ? NumeralConvert.PersianDigits(date) : date);
        }
示例#4
0
        public static string GregorianToPersian(DateTime gregorianDate, string format, bool persianDigits = true)
        {
            int year  = calendar.GetYear(gregorianDate);
            int month = calendar.GetMonth(gregorianDate);
            int day   = calendar.GetDayOfMonth(gregorianDate);

            var date = new StringBuilder(format);

            date.Replace("ddd", PersianWeekday(gregorianDate));
            date.Replace("dd", day.ToString("00"));
            date.Replace("d", day.ToString());
            date.Replace("mmm", PersianMonth(month));
            date.Replace("mm", month.ToString("00"));
            date.Replace("m", month.ToString());
            date.Replace("yyyy", year.ToString());
            date.Replace("yy", (year % 100).ToString());
            return(persianDigits ? NumeralConvert.PersianDigits(date) : date.ToString());
        }