تبديل ميلادي به شمسي و بالعكس

mohsena

New Member
سلام من با كلد فيوژن صفحات وب را مي نويسم .من چند functionامتحان كردم ولي هنوز در تبديل ميلادي به شمسي و عكس اشكال دارم آيا function يا راه مطمپني مي شناسيد .در ضمن درمورد كلد فيوژن در خدمتم
 

AliReza26

Active Member
اين با ASP :


کد:
<% 
Function persian_weekday(iYear, iMonth, iDay) 
    jdn = persian_jdn(iYear, iMonth, iDay) 
    jdn = ((jdn + 1) MOD 7) 
    persian_weekday = jdn + 2 
    if persian_weekday = 8 then 
        persian_weekday = 1 
    end if 
End Function 

Sub jdn_persian(jdn , iYear, iMonth, iDay) 
    depoch = jdn - persian_jdn(475, 1, 1) 
    cycle = Fix(depoch / 1029983) 
    cyear = depoch Mod 1029983 
    If cyear = 1029982 Then 
        ycycle = 2820 
    Else 
        aux1 = Fix(cyear / 366) 
        aux2 = cyear Mod 366 
        ycycle = Int(((2134 * aux1) + (2816 * aux2) + 2815) / 1028522) + aux1 + 1 
    End If 
    iYear = ycycle + (2820 * cycle) + 474 
    If iYear <= 0 Then 
        iYear = iYear - 1 
    End If 
    yday = (jdn - persian_jdn(iYear, 1, 1)) + 1 
    If yday <= 186 Then 
        iMonth = Ceil(yday / 31) 
    Else 
        iMonth = Ceil((yday - 6) / 30) 
    End If 
    iDay = (jdn - persian_jdn(iYear, iMonth, 1)) + 1 
End Sub 

Private Function Ceil(number) 
    Ceil = -Sgn(number) * Int(-Abs(number)) 
End Function 

Function persian_jdn(iYear, iMonth, iDay) 
    If iYear >= 0 Then 
        epbase = iYear - 474 
    Else 
        epbase = iYear - 473 
    End If 
    epyear = 474 + (epbase Mod 2820) 
    If iMonth <= 7 Then 
        mdays = (CLng(iMonth) - 1) * 31 
    Else 
        mdays = (CLng(iMonth) - 1) * 30 + 6 
    End If 
    persian_jdn = CLng(iDay) + mdays + Fix(((epyear * 682) - 110) / 2816) + (epyear - 1) * 365 + Fix(epbase / 2820) * 1029983 + (1948321 - 1) 
End Function 

Function civil_jdn(iYear, iMonth, iDay) 
   If ((iYear > 1582) Or ((iYear = 1582) And (iMonth > 10)) Or ((iYear = 1582) And (iMonth = 10) And (iDay > 14))) Then 
        lYear = CLng(iYear) 
        lMonth = CLng(iMonth) 
        lDay = CLng(iDay) 
        civil_jdn = ((1461 * (lYear + 4800 + ((lMonth - 14) \ 12))) \ 4) + ((367 * (lMonth - 2 - 12 * (((lMonth - 14) \ 12)))) \ 12) - ((3 * (((lYear + 4900 + ((lMonth - 14) \ 12)) \ 100))) \ 4) + lDay - 32075 
    Else 
        civil_jdn = julian_jdn(iYear, iMonth, iDay) 
    End If 
End Function 

Function julian_jdn(iYear, iMonth, iDay) 
    lYear = CLng(iYear) 
    lMonth = CLng(iMonth) 
    lDay = CLng(iDay) 
    julian_jdn = 367 * lYear - ((7 * (lYear + 5001 + ((lMonth - 9) \ 7))) \ 4) + ((275 * lMonth) \ 9) + lDay + 1729777 
End Function 

Sub jdn_civil(jdn, iyear, imonth, iday) 
    If (jdn > 2299160) Then 
        l = jdn + 68569 
        n = ((4 * l) \ 146097) 
        l = l - ((146097 * n + 3) \ 4) 
        i = ((4000 * (l + 1)) \ 1461001) 
        l = l - ((1461 * i) \ 4) + 31 
        j = ((80 * l) \ 2447) 
        iday = l - ((2447 * j) \ 80) 
        l = (j \ 11) 
        imonth = j + 2 - 12 * l 
        iyear = 100 * (n - 49) + i + l 
    Else 
        Call jdn_julian(jdn, iyear, imonth, iday) 
    End If 
End Sub 

Sub jdn_julian(jdn, iYear, iMonth, iDay) 
    j = jdn + 1402 
    k = ((j - 1) \ 1461) 
    l = j - 1461 * k 
    n = ((l - 1) \ 365) - (l \ 1461) 
    i = l - 365 * n + 30 
    j = ((80 * i) \ 2447) 
    iDay = i - ((2447 * j) \ 80) 
    i = (j \ 11) 
    iMonth = j + 2 - 12 * i 
    iYear = 4 * k + n + i - 4716 
End Sub 

Sub civil_persian(iYear, iMonth, iDay) 
   Call jdn_persian(civil_jdn(iYear, iMonth, iDay), iYear, iMonth, iDay) 
End Sub 

Sub persian_civil(iYear, iMonth, iDay) 
   Call jdn_civil(persian_jdn(iYear, iMonth, iDay), iYear, iMonth, iDay) 
End Sub 

Function persian_WeekName(iWeek) 
    Select Case iWeek 
    Case 1 persian_WeekName = "شنبه" 
    Case 2 persian_WeekName = "يكشنبه" 
    Case 3 persian_WeekName = "دوشنبه" 
    Case 4 persian_WeekName = "سه شنبه" 
    Case 5 persian_WeekName = "چهارشنبه" 
    Case 6 persian_WeekName = "پنجشنبه" 
    Case 7 persian_WeekName = "جمعه" 
    Case Else persian_WeekName = "Error" 
    End Select 
End Function 

Function persian_MonthName(iMonth) 
    Select Case iMonth 
    Case 1 
        persian_MonthName = "فروردين" 
    Case 2 
        persian_MonthName = "اردی بهشت" 
    Case 3 
        persian_MonthName = "خرداد" 
    Case 4 
        persian_MonthName = "تير" 
    Case 5 
        persian_MonthName = "مرداد" 
    Case 6 
        persian_MonthName = "شهريور" 
    Case 7 
        persian_MonthName = "مهر" 
    Case 8 
        persian_MonthName = "آبان" 
    Case 9 
        persian_MonthName = "آذر" 
    Case 10 
        persian_MonthName = "دى" 
    Case 11 
        persian_MonthName = "بهمن" 
    Case 12 
        persian_MonthName = "اسفند" 
    Case Else 
        persian_MonthName = "Error" 
    End Select 
End Function 



'*************************************************************************************************** 


datetime = date + timeserial (hour(now), minute(now) , second(now)) 
nDay = day(datetime ) 'day in persian time ! 
nMonth = month(datetime ) 'mounth in persian time 
nYear = year(datetime ) 'year in persian time ! 
call civil_persian(nYear, nMonth, nDay) 
nWeekday = persian_Weekname(persian_weekday(nYear, nMonth, nDay)) 
nMonth = persian_Monthname(nMonth) 
Today = nWeekday & " " & nDay & " " & nMonth & " " & nYear & " "' & "  ساعت  :  " & hour(datetime) & ":" & minute(datetime)' & " - " & WeekDayName(WeekDay(datetime), TRUE) & " " & MonthName(Month(datetime), TRUE) & " " & Day(datetime) & " " &Year(datetime) & " " 
response.Write(today) 
%>

اينم يكي ديگه :

کد:
<% 
'######################################### 
'///////////////////////// 
'////////AliReza26//////// 
'////////Tarahi.net/////// 
'///////////////////////// 
'######################################### 

'@@@@@  Begin   @@@@@ 

function days() 

Dim stryear, strmonth, strday 

        If Month(Now) = 4 Or Month(Now) = 5 Or Month(Now) = 6 Or Month(Now) = 7 Or Month(Now) = 8 Or Month(Now) = 9 Or Month(Now) = 10 Or Month(Now) = 11 Or Month(Now) = 12 Then 
            stryear = Year(Now) - 621 
        ElseIf Month(Now) = 1 Or Month(Now) = 2 Then 
            stryear = Year(Now) - 622 
        ElseIf Month(Now) = 3 Then 
            If day(now) > 19 Then 
                stryear = Year(Now) - 621 
            Else 
                stryear = Year(Now) - 622 
            End If 
        End If 


        If Month(Now) = 4 Then 
            If day(now) <= 19 Then 
                strday = day(now) + 12 
                strmonth = "فروردین" 
            Else 
                strday = day(now) - 19 
                strmonth = "اردیبهشت" 
            End If 


        ElseIf Month(Now) = 5 Then 
            If day(now) <= 20 Then 
                strday = day(now) + 11 
                strmonth = "اردیبهشت" 
            Else 
                strday = day(now) - 20 
                strmonth = "خرداد" 
            End If 


        ElseIf Month(Now) = 6 Then 
            If day(now) <= 20 Then 
                strday = day(now) + 11 
                strmonth = "خرداد" 
            Else 
                strday = day(now) - 20 
                strmonth = "تیر" 
            End If 


        ElseIf Month(Now) = 7 Then 
            If day(now) <= 21 Then 
                strday = day(now) + 10 
                strmonth = "تیر" 
            Else 
                strday = day(now) - 21 
                strmonth = "مرداد" 
            End If 


        ElseIf Month(Now) = 8 Then 
            If day(now) <= 21 Then 
                strday = day(now) + 10 
                strmonth = "مرداد" 
            Else 
                strday = day(now) - 21 
                strmonth = "شهریور" 
            End If 


        ElseIf Month(Now) = 9 Then 
            If day(now) <= 21 Then 
                strday = day(now) + 10 
                strmonth = "شهریور" 
            Else 
                strday = day(now) - 21 
                strmonth = "مهر" 
            End If 



        ElseIf Month(Now) = 10 Then 
            If day(now) <= 21 Then 
                strday = day(now) + 9 
                strmonth = "مهر" 
            Else 
                strday = day(now) - 21 
                strmonth = "آبان" 
            End If 


        ElseIf Month(Now) = 11 Then 
            If day(now) <= 20 Then 
                strday = day(now) + 10 
                strmonth = "آبان" 
            Else 
                strday = day(now) - 20 
                strmonth = "آذر" 
            End If 


        ElseIf Month(Now) = 12 Then 
            If day(now) <= 20 Then 
                strday = day(now) + 10 
                strmonth = "آذر" 
            Else 
                strday = day(now) - 20 
                strmonth = "دی" 
            End If 


        ElseIf Month(Now) = 1 Then 
            If day(now) <= 19 Then 
                strday = day(now) + 11 
                strmonth = "دی" 
            Else 
                strday = day(now) - 19 
                strmonth = "بهمن" 
            End If 


        ElseIf Month(Now) = 2 Then 
            If day(now) <= 18 Then 
                strday = day(now) + 12 
                strmonth = "بهمن" 
            Else 
                strday = day(now) - 18 
                strmonth = "اسفند" 
            End If 


        ElseIf Month(Now) = 3 Then 
            If day(now) <= 19 Then 
                strday = day(now) + 10 
                strmonth = "اسفند" 
            Else 
                strday = day(now) - 19 
                strmonth = "فروردین" 
            End If 


        End If 

       dim strrozehafte 

        If Weekday(Now) = 7 Then 
            strrozehafte = "شنبه" 
        ElseIf Weekday(Now) = 1 Then 
            strrozehafte = "یکشنبه" 
        ElseIf Weekday(Now) = 2 Then 
            strrozehafte = "دوشنبه" 
        ElseIf Weekday(Now) = 3 Then 
            strrozehafte = "سه شنبه" 
        ElseIf Weekday(Now) = 4 Then 
            strrozehafte = "چهار شنبه" 
        ElseIf Weekday(Now) = 5 Then 
            strrozehafte = "پنج شنبه" 
        ElseIf Weekday(Now) = 6 Then 
            strrozehafte = "جمعه" 
        End If 



        strtaghvim =     " امروز" & " : " & strrozehafte & " " & strday &  " " & strmonth & " " &  stryear 
        response.write(strtaghvim) 

end function 

'@@@@@   END    @@@@@ 
'########################################################################### 







'@@@@@    Callin function     @@@@@ 


call days() 

%>
 

Mikhak

Active Member
اين با php
اين تابعش
اينم يه جور تابعه ديگه:)

کد:
."<script type=\"text/javascript\">\n\n"
  		."function showdate() { "
		."week= new Array(\"يكشنبه\",\"دوشنبه\",\"سه شنبه\",\"چهارشنبه\",\"پنج شنبه\",\"جمعه\",\"شنبه\"); "
		."months = new Array(\"فروردين\",\"ارديبهشت\",\"خرداد\",\"تير\",\"مرداد\",\"شهريور\",\"مهر\",\"آبان\",\"آذر\",\"دي\",\"بهمن\",\"اسفند\");" 
		."a = new Date(); "
		."d= a.getDay(); "
		."day= a.getDate(); "
		."month = a.getMonth()+1; "
		."year= a.getYear(); "
		."year = (year== 0)?2000:year; "
		."(year<1000)? (year += 2000):true; "
		
		."year -= ( (month < 3) || ((month == 3) && (day < 21)) )? 622:621; "
		."switch (month) { "
		."case 1: (day<21)? (month=10, day+=10):(month=11, day-=20); break; "
		."case 2: (day<20)? (month=11, day+=11):(month=12, day-=19); break; "
		."case 3: (day<21)? (month=12, day+=9):(month=1, day-=20); break; "
		."case 4: (day<21)? (month=1, day+=11):(month=2, day-=20); break; "
		."case 5: "
		."case 6: (day<22)? (month-=3, day+=10):(month-=2, day-=21); break; "
		."case 7: "
		."case 8: "
		."case 9: (day<23)? (month-=3, day+=9):(month-=2, day-=22); break;" 
		."case 10:(day<23)? (month=7, day+=8):(month=8, day-=22); break; "
		."case 11: "
		."case 12:(day<22)? (month-=3, day+=9):(month-=2, day-=21); break; "
		."default: break;" 
		."}"
		
		."y1=0;while(year>1000){year=year-1000;y1++;}"
		."y2=0;while(year>100){year=year-100;y2++;}"
		."y3=0;while(year>10){year=year-10;y3++;}"
		."switch (y1) { "
		."case 1: y1=\"۱\"; break;"
		."case 2: y1=\"۲\"; break;"
		."case 3: y1=\"۳\"; break;"
		."case 4: y1=\"۴\"; break;"
		."case 5: y1=\"۵\"; break;"
		."case 6: y1=\"۶\"; break;"
		."case 7: y1=\"۷\"; break;"
		."case 8: y1=\"۸\"; break;"
		."case 9: y1=\"۹\"; break;"
		."default: break; "
		."}"
		."switch (y2) { "
		."case 1: y2=\"۱\"; break;"
		."case 2: y2=\"۲\"; break;"
		."case 3: y2=\"۳\"; break;"
		."case 4: y2=\"۴\"; break;"
		."case 5: y2=\"۵\"; break;"
		."case 6: y2=\"۶\"; break;"
		."case 7: y2=\"۷\"; break;"
		."case 8: y2=\"۸\"; break;"
		."case 9: y2=\"۹\"; break;"
		."default: break;"
		." }"
		."switch (y3) { "
		."case 1: y3=\"۱\"; break;"
		."case 2: y3=\"۲\"; break;"
		."case 3: y3=\"۳\"; break;"
		."case 4: y3=\"۴\"; break;"
		."case 5: y3=\"۵\"; break;"
		."case 6: y3=\"۶\"; break;"
		."case 7: y3=\"۷\"; break;"
		."case 8: y3=\"۸\"; break;"
		."case 9: y3=\"۹\"; break;"
		."default: break;"
		." }"
		."switch (year) { "
		."case 1: year=\"۱\"; break;"
		."case 2: year=\"۲\"; break;"
		."case 3: year=\"۳\"; break;"
		."case 4: year=\"۴\"; break;"
		."case 5: year=\"۵\"; break;"
		."case 6: year=\"۶\"; break;"
		."case 7: year=\"۷\"; break;"
		."case 8: year=\"۸\"; break;"
		."case 9: year=\"۹\"; break;"
		."default: break; "
		."}"
		."d1=0;while(day>10){day=day-10;d1++;}"
		."switch (d1) { "
		."case 1: d1=\"۱\"; break;"
		."case 2: d1=\"۲\"; break;"
		."case 3: d1=\"۳\"; break;"
		."case 4: d1=\"۴\"; break;"
		."case 5: d1=\"۵\"; break;"
		."case 6: d1=\"۶\"; break;"
		."case 7: d1=\"۷\"; break;"
		."case 8: d1=\"۸\"; break;"
		."case 9: d1=\"۹\"; break;"
		."default: break; "
		."}"
		."switch (day) { "
		."case 1: day=\"۱\"; break;"
		."case 2: day=\"۲\"; break;"
		."case 3: day=\"۳\"; break;"
		."case 4: day=\"۴\"; break;"
		."case 5: day=\"۵\"; break;"
		."case 6: day=\"۶\"; break;"
		."case 7: day=\"۷\"; break;"
		."case 8: day=\"۸\"; break;"
		."case 9: day=\"۹\"; break;"
		."default: break; "
		."}"
		 
		."document.write(\" \"+week[d]+\" \"+d1,day+\" \"+months[month-1]+\" \"+ y1,y2,y3,year); "
		."}"
		."</script>"

اينم طريقه استفاده
کد:
."<script>showdate()</script>"
----------------
سينا
 

Mikhak

Active Member
اينم با javascript
اين تابعش
کد:
<script> 
function showdate() { 

week= new Array("يكشنبه","دوشنبه","سه شنبه","چهارشنبه","پنج شنبه","جمعه","شنبه") 
months = new Array("فروردين","ارديبهشت","خرداد","تير","مرداد","شهريور","مهر","آبان","آذر","دي","بهمن","اسفند"); 
a = new Date(); 
d= a.getDay(); 
day= a.getDate(); 
month = a.getMonth()+1; 
year= a.getYear(); 
year = (year== 0)?2000:year; 
(year<1000)? (year += 2000):true; 
year -= ( (month < 3) || ((month == 3) && (day < 21)) )? 622:621; 
switch (month) { 
case 1: (day<21)? (month=10, day+=10):(month=11, day-=20); break; 
case 2: (day<20)? (month=11, day+=11):(month=12, day-=19); break; 
case 3: (day<21)? (month=12, day+=9):(month=1, day-=20); break; 
case 4: (day<21)? (month=1, day+=11):(month=2, day-=20); break; 
case 5: 
case 6: (day<22)? (month-=3, day+=10):(month-=2, day-=21); break; 
case 7: 
case 8: 
case 9: (day<23)? (month-=3, day+=9):(month-=2, day-=22); break; 
case 10:(day<23)? (month=7, day+=8):(month=8, day-=22); break; 
case 11: 
case 12:(day<22)? (month-=3, day+=9):(month-=2, day-=21); break; 
default: break; 
} 
y1=0;while(year>1000){year=year-1000;y1++;}
y2=0;while(year>100){year=year-100;y2++;}
y3=0;while(year>10){year=year-10;y3++;}
switch (y1) { 
case 1: y1="۱"; break; 
case 2: y1="۲"; break; 
case 3: y1="۳"; break;
case 4: y1="۴"; break;
case 5: y1="۵"; break;
case 6: y1="۶"; break;
case 7: y1="۷"; break;
case 8: y1="۸"; break;
case 9: y1="۹"; break;
default: break; 
} 
switch (y2) { 
case 1: y2="۱"; break; 
case 2: y2="۲"; break; 
case 3: y2="۳"; break;
case 4: y2="۴"; break;
case 5: y2="۵"; break;
case 6: y2="۶"; break;
case 7: y2="۷"; break;
case 8: y2="۸"; break;
case 9: y2="۹"; break;
default: break; 
} 
switch (y3) { 
case 1: y3="۱"; break; 
case 2: y3="۲"; break; 
case 3: y3="۳"; break;
case 4: y3="۴"; break;
case 5: y3="۵"; break;
case 6: y3="۶"; break;
case 7: y3="۷"; break;
case 8: y3="۸"; break;
case 9: y3="۹"; break;
default: break; 
} 
switch (year) { 
case 1: year="۱"; break; 
case 2: year="۲"; break; 
case 3: year="۳"; break;
case 4: year="۴"; break;
case 5: year="۵"; break;
case 6: year="۶"; break;
case 7: year="۷"; break;
case 8: year="۸"; break;
case 9: year="۹"; break;
default: break; 
} 
d1=0;while(day>10){day=day-10;d1++;}
switch (d1) { 
case 1: d1="۱"; break; 
case 2: d1="۲"; break; 
case 3: d1="۳"; break;
case 4: d1="۴"; break;
case 5: d1="۵"; break;
case 6: d1="۶"; break;
case 7: d1="۷"; break;
case 8: d1="۸"; break;
case 9: d1="۹"; break;
default: break; 
} 
switch (day) { 
case 1: day="۱"; break; 
case 2: day="۲"; break; 
case 3: day="۳"; break;
case 4: day="۴"; break;
case 5: day="۵"; break;
case 6: day="۶"; break;
case 7: day="۷"; break;
case 8: day="۸"; break;
case 9: day="۹"; break;
default: break; 
} 
document.write(" "+week[d]+" "+d1,day+" "+months[month-1]+" "+ y1,y2,y3,year);
} 
</script>

اينم طريقه استفادش
کد:
<script>showdate()</script>

------------------
سينا
 

جدیدترین ارسال ها

بالا