• 0 رای - 0 میانگین
  • 1
  • 2
  • 3
  • 4
  • 5
مشکل با jalali_to_gregorian
#1
Wink 
با عرض سلام و خسته نباشید خدمت اساتید محترم
من یک مشکلی دارم با jalali_to_gregorian در موقع تبدیل تاریخ جلالی به میلادی میخوام اعدادی که یک رقمی می باشد 0 بگذارد سرچ هم کردم ولی چیزی پیدا نکردم
مثال :
16/09/1395
نتیجه
2016/12/6
الان میخوام قبل از 6 یک 0 بزاره
2016/12/06
اگر هم لطف کنید بگید چجوری میشه 2016 رو 20 را حذف کرد
باتشکر
  پاسخ
تشکر شده توسط :
#2
کلاس رو حفظ نیستم که اسم متد رو بگم ولی متدی که خروجی ماه و روز رو برمیگردونه رو به صورت زیر ویرایش کن

کد پی‌اچ‌پی:
if(strlen($variable) == 1){
    
$variable '0'.$variable;


برای سال هم کد زیر

کد پی‌اچ‌پی:
$variable substr($variable2); 
  پاسخ
تشکر شده توسط : Alaa mahdisa300 kasbookar ayoubsys
#3
با تشکر ولی من اومدم همچین کاری رو انجام دادم


کد:
    $datepicker4 = $_POST['datepicker4'];
    $date_arr = explode('/',$datepicker4);    
    $arr_gregorian = jalali_to_gregorian("0". $date_arr[2],"0".$date_arr[1],"0".$date_arr[0]);
    $dat_1 = jalali_to_gregorian($date_arr[0]);
    $dat_2 = jalali_to_gregorian($date_arr[2]);
    $dat_2 = jalali_to_gregorian($date_arr[1]);
    echo $dat_1;
        switch ($dat_1) {
        case "1":
            $dat = "01";
            break;
        case "2":
            $dat = "02";
            break;
        case "3":
            $dat = "03";
            break;
                    case "4":
            $dat = "04";
            break;
                    case "5":
            $dat = "05";
            break;
                    case "6":
            $dat = "06";
            break;
                    case "7":
            $dat = "07";
            break;
                    case "8":
            $dat = "08";
            break;
                    case "9":
            $dat = "09";
            break;
                                case "10":
            $dat = "10";
            break;
                                case "11":
            $dat = "11";
            break;
        default :
            $dat = "12";
    }
    
        switch ($dat_2) {
        case "1":
            $dat1 = "01";
            break;
        case "2":
            $dat1 = "02";
            break;
        case "3":
            $dat1 = "03";
            break;
                    case "4":
            $dat1 = "04";
            break;
                    case "5":
            $dat1 = "05";
            break;
                    case "6":
            $dat1 = "06";
            break;
                    case "7":
            $dat1 = "07";
            break;
                    case "8":
            $dat1 = "08";
            break;
                    case "9":
            $dat1 = "09";
            break;
                                case "10":
            $dat1 = "10";
            break;
            case "11":
            $dat1 = "11";
            break;
                        case "12":
            $dat1 = "12";
            break;
                        case "13":
            $dat1 = "13";
            break;
                        case "14":
            $dat1 = "14";
            break;
                        case "15":
            $dat1 = "15";
            break;
                        case "16":
            $dat1 = "16";
            break;
                        case "17":
            $dat1 = "17";
            break;
                        case "18":
            $dat1 = "18";
            break;
                        case "19":
            $dat1 = "19";
            break;
                        case "20":
            $dat1 = "20";
            break;
                        case "21":
            $dat1 = "21";
            break;
                        case "22":
            $dat1 = "22";
            break;
                        case "23":
            $dat1 = "23";
            break;
                        case "24":
            $dat1 = "24";
            break;
                        case "25":
            $dat1 = "25";
            break;
                        case "26":
            $dat1 = "26";
            break;
                        case "27":
            $dat1 = "27";
            break;
                        case "28":
            $dat1 = "28";
            break;
                        case "30":
            $dat1 = "30";
            break;
                        case "31":
            $dat1 = "31";
            break;
        default :
            $dat1 = "12";
    }

    echo "*********". $dat ."******". $dat1 ."******";
  پاسخ
تشکر شده توسط :
#4
با عرض سلام و خسته نباشید من مشکلم حل شد !

کد:
    $datepicker4 = $_POST['datepicker4'];
    $date_arr = explode('/',$datepicker4);    
    $arr_gregorian = jalali_to_gregorian($date_arr[2],$date_arr[1],$date_arr[0]);
    $dat_1 = $arr_gregorian[2];
    $dat_2 = $arr_gregorian[1];
    $dat_3 = $arr_gregorian[0];
    $dat_3_year = substr($dat_3, 2);
        switch ($dat_1) {
        case 1:
            $dat = "01";
            break;
        case 2:
            $dat = "02";
            break;
        case 3:
            $dat = "03";
            break;
                    case 4:
            $dat = "04";
            break;
                    case 5:
            $dat = "05";
            break;
                    case 6:
            $dat = "06";
            break;
                    case 7:
            $dat = "07";
            break;
                    case 8:
            $dat = "08";
            break;
                    case 9:
            $dat = "09";
            break;
                    case 10:
            $dat = "10";
            break;
                    case 11:
            $dat = "11";
            break;
        default :
            $dat = "12";
    }
    
        switch ($dat_2) {
                    case 1:
            $dat1 = "01";
            break;
                    case 2:
            $dat1 = "02";
            break;
                    case 3:
            $dat1 = "03";
            break;
                    case 4:
            $dat1 = "04";
            break;
                    case 5:
            $dat1 = "05";
            break;
                    case 6:
            $dat1 = "06";
            break;
                    case 7:
            $dat1 = "07";
            break;
                    case 8:
            $dat1 = "08";
            break;
                    case 9:
            $dat1 = "09";
            break;
                    case 10:
            $dat1 = "10";
            break;
                    case 11:
            $dat1 = "11";
            break;
                        case 12:
            $dat1 = "12";
            break;
                        case 13:
            $dat1 = "13";
            break;
                        case 14:
            $dat1 = "14";
            break;
                        case 15:
            $dat1 = "15";
            break;
                        case 16:
            $dat1 = "16";
            break;
                        case 17:
            $dat1 = "17";
            break;
                        case 18:
            $dat1 = "18";
            break;
                        case 19:
            $dat1 = "19";
            break;
                        case 20:
            $dat1 = "20";
            break;
                        case 21:
            $dat1 = "21";
            break;
                        case 22:
            $dat1 = "22";
            break;
                        case 23:
            $dat1 = "23";
            break;
                        case 24:
            $dat1 = "24";
            break;
                        case 25:
            $dat1 = "25";
            break;
                        case 26:
            $dat1 = "26";
            break;
                        case 27:
            $dat1 = "27";
            break;
                        case 28:
            $dat1 = "28";
            break;
                        case 30:
            $dat1 = "30";
            break;
                        case 31:
            $dat1 = "31";
            break;
        default :
            $dat1 = "12";
    }
$dater=$dat1."/".$dat."/".$dat_3_year ;
باتشکر Heart
  پاسخ
تشکر شده توسط :
#5
فرق کد من و شما در performance هست وگرنه جفتش درست کار میکنه
اگر جای switch case به تعداد شرط if هم بزارید درست کار میکنه ولی همون بحث قبلی بین این دو شرط
  پاسخ
تشکر شده توسط :


پرش به انجمن:


کاربران در حال بازدید این موضوع: 1 مهمان