Calendar-Converter西曆和農曆互轉JavaScript外掛程式使用例子

來源:互聯網
上載者:User

Calendar-Converter是一個簡單的外掛程式,可能只有中文的應用或者網站才會用到這個外掛程式,這個外掛程式的功能就是在西曆和農曆之間,進行日期時間轉換。

使用樣本

首先引入外掛程式檔案

<script src="js/calendar-converter.js"></script>
然後執行個體化外掛程式對象,傳遞一個時間對象

var cc = new CalendarConverter;
cc.solar2lunar(new Date(2011, 0, 3)); ---> 2010,11,29
cc.lunar2solar(new Date(2010, 10, 29)); ----> 2011, 1, 3
農曆轉西曆時,如果那一月是那一年的閏月,則需額外傳一個參數,才能得到正確的西曆日期

cc.solar2lunar(new Date(2012, 4, 27)); ---> 2012年5月初7, 其中 isLeap為true,表示為閏四月
cc.lunar2solar(new Date(2012, 3, 7)) ---> 得到錯誤時間:2012, 4, 27
cc.lunar2solar(new Date(2012, 3, 7), true) --> 正確: 2012, 5, 27
選擇性參數

result:{
    cDay:"戊戌"
    ,cMonth:"丁未"
    ,cYear:"壬辰"
    ,isLeap:false//該月是否為閏月
    ,lDay:18
    ,lMonth:6
    ,lYear:2012
    ,lunarDay:"十八"
    ,lunarFestival:""
    ,lunarMonth:"六"
    ,lunarYear:"龍"
    ,sDay:5
    ,sMonth:8
    ,sYear:2012,solarFestival:""//節日(Festivals)
    ,solarTerms:""//節氣
    ,week:"日"//周幾
}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.