2014-07-16 3 views
1

자바 스크립트에서 getfullyear() 대신 사용자 정의 함수를 호출하고 싶습니다. 어떻게해야합니까? 요점은 그레고리 안 캘린더를 jomsocial에서 jallali로 변경하는 것입니다. 예를 들어 나는이 내가 호출 할 함수가 1393/6/25자바 스크립트에서 getfullyear() 대신 사용자 정의 함수가 호출됩니다.

되었다 싶어,이

d=new Date(b.year,b.month,b.date+a);c.set("highlight",JalaliDate[d.getFullYear(),d.getMonth(),d.getDate()] 

결과는 2014/16/7 될 것입니다 쓸 때 http://www.farsiweb.info/jalali/jalali.js 또는

jQuery(function($){ 
$.datepicker.regional['fa'] = { 
    calendar: JalaliDate, 
    closeText: 'بستن', 
    prevText: 'قبل', 
    nextText: 'بعد', 
    currentText: 'امروز', 
    monthNames: ['فروردین','اردیبهشت','خرداد','تیر','مرداد','شهریور','مهر','آبان','آذر','دی','بهمن','اسفند'], 
    monthNamesShort: ['فروردین','اردیبهشت','خرداد','تیر','مرداد','شهریور','مهر','آبان','آذر','دی','بهمن','اسفند'], 
    dayNames: ['یکشنبه', 'دوشنبه', 'سه شنبه', 'چهارشنبه', 'پنجشنبه', 'جمعه', 'شنبه'], 
    dayNamesShort: ['یک', 'دو', 'سه', 'چهار', 'پنج', 'جمعه', 'شنبه'], 
    dayNamesMin: ['ی','د','س','چ','پ','ج','ش'], 
    weekHeader: 'ه', 
    dateFormat: 'dd/mm/yy', 
    firstDay: 6, 
    isRTL: true, 
    showMonthAfterYear: false, 
    yearSuffix: '', 
    calculateWeek: function(date) { 
     var checkDate = new JalaliDate(date.getFullYear(), date.getMonth(), date.getDate() + (date.getDay() || 7) - 3); 
     return Math.floor(Math.round((checkDate.getTime() - new JalaliDate(checkDate.getFullYear(), 0, 1).getTime())/86400000)/7) + 1; 
    }}; 
$.datepicker.setDefaults($.datepicker.regional['fa']); }); 
function JalaliDate(p0, p1, p2) { 
var gregorianDate; 
var jalaliDate; 

if (!isNaN(parseInt(p0)) && !isNaN(parseInt(p1)) && !isNaN(parseInt(p2))) { 
    var g = jalali_to_gregorian([parseInt(p0, 10), parseInt(p1, 10), parseInt(p2, 10)]); 
    setFullDate(new Date(g[0], g[1], g[2])); 
} else { 
    setFullDate(p0); 
} 

function jalali_to_gregorian(d) { 
    var adjustDay = 0; 
    if(d[1]<0){ 
     adjustDay = leap_persian(d[0]-1)? 30: 29; 
     d[1]++; 
    } 
    var gregorian = jd_to_gregorian(persian_to_jd(d[0], d[1] + 1, d[2])-adjustDay); 
    gregorian[1]--; 
    return gregorian; 
} 

function gregorian_to_jalali(d) { 
    var jalali = jd_to_persian(gregorian_to_jd(d[0], d[1] + 1, d[2])); 
    jalali[1]--; 
    return jalali; 
} 

function setFullDate(date) { 
    if (date && date.getGregorianDate) date = date.getGregorianDate(); 
    gregorianDate = new Date(date); 
    gregorianDate.setHours(gregorianDate.getHours() > 12 ? gregorianDate.getHours() + 2 : 0) 
    if (!gregorianDate || gregorianDate == 'Invalid Date' || isNaN(gregorianDate || !gregorianDate.getDate())) { 
     gregorianDate = new Date(); 
    } 
    jalaliDate = gregorian_to_jalali([ 
     gregorianDate.getFullYear(), 
     gregorianDate.getMonth(), 
     gregorianDate.getDate()]); 
    return this; 
} 

this.getGregorianDate = function() { return gregorianDate; } 

this.setFullDate = setFullDate; 

this.setMonth = function(e) { 
    jalaliDate[1] = e; 
    var g = jalali_to_gregorian(jalaliDate); 
    gregorianDate = new Date(g[0], g[1], g[2]); 
    jalaliDate = gregorian_to_jalali([g[0], g[1], g[2]]); 
} 

this.setDate = function(e) { 
    jalaliDate[2] = e; 
    var g = jalali_to_gregorian(jalaliDate); 
    gregorianDate = new Date(g[0], g[1], g[2]); 
    jalaliDate = gregorian_to_jalali([g[0], g[1], g[2]]); 
}; 

this.getFullYear = function() { return jalaliDate[0]; }; 
this.getMonth = function() { return jalaliDate[1]; }; 
this.getDate = function() { return jalaliDate[2]; }; 
this.toString = function() { return jalaliDate.join(',').toString(); }; 
this.getDay = function() { return gregorianDate.getDay(); }; 
this.getHours = function() { return gregorianDate.getHours(); }; 
this.getMinutes = function() { return gregorianDate.getMinutes(); }; 
this.getSeconds = function() { return gregorianDate.getSeconds(); }; 
this.getTime = function() { return gregorianDate.getTime(); }; 
this.getTimeZoneOffset = function() { return gregorianDate.getTimeZoneOffset(); }; 
this.getYear = function() { return jalaliDate[0] % 100; }; 

this.setHours = function(e) { gregorianDate.setHours(e) }; 
this.setMinutes = function(e) { gregorianDate.setMinutes(e) }; 
this.setSeconds = function(e) { gregorianDate.setSeconds(e) }; 
this.setMilliseconds = function(e) { gregorianDate.setMilliseconds(e) }; } 

감사합니다.

답변

0

0123을 사용하는 경우, 시도하십시오

function printJalali(year, month, day) { 
    var jalali = gregorian_to_jalali([year, month+1, day]); 
    return jalali[0] + "/" + jalali[1] + "/" + jalali[2]; 
} 

var today = new Date(); 
alert(printJalali(today.getFullYear(), today.getMonth(), today.getDate()));