Để tính nhẩm năm dương lịch sang năm âm lịch ta làm 2 bước: Tính chi và tính can.

Chi từ 0 đến 11 gồm: Tý, Sửu, Dần, Mão, Thìn, Tị, Ngọ, Mùi, Thân,Dậu Tuất, Hợi. Cách tính chi ta lấy 2 số cuối của năm dương, nếu năm lớn hơn 2000 thì cộng thêm 4. Chia cho 12 lấy số dư. So với bảng chi ta được năm âm.

Can từ 0 đến 9 gồm: Giáp, Ất, Bính, Đinh, Mậu, Kỷ, Canh, Tân, Nhâm, Quý. Ta lấy số cuối của năm dương cộng với 6 rồi ta lấy số cuối của kết quả so với bảng can. Ghép Can và Chi tìm được ta có kết quả năm âm lịch

Sau đây là mô phỏng bằng Javascript
Hãy nhập năm (1900 - nay) muốn tính năm âm lịch
Bước 1: Chúng ta đi tìm Can
  • ?
  • ?
  • +
  • 6
  • ?
  • ?
Bước 2: Chúng ta đi tìm chi
  • ?
  • ?
  • ?
  • ?
  • ?
  • 2
  • 0
  • 0
  • 0
  • ?
  • ?
  • +
  • 4
  • ?
  • ?
  • ?
  • ?
  • :
  • 1
  • 2
  • ?
  • ?
  • ?
  • ?
Stt Can
Stt Chi

Click vào đây để xem nội dung code mô phỏng

1. Code javascript
var CalculatorLunarCalendar = function ()
{
    var chi = {};
    chi[0] = { name: "Tý" };
    chi[1] = { name: "Sửu" };
    chi[2] = { name: "Dần" };
    chi[3] = { name: "Mão" };
    chi[4] = { name: "Thìn" };
    chi[5] = { name: "Tị" };
    chi[6] = { name: "Ngọ" };
    chi[7] = { name: "Mùi" };
    chi[8] = { name: "Thân" };
    chi[9] = { name: "Dậu" };
    chi[10] = { name: "Tuất" };
    chi[11] = { name: "Hợi" };

    var can = {};
    can[0] = { name: "Giáp" };
    can[1] = { name: "Ất" };
    can[2] = { name: "Bính" };
    can[3] = { name: "Đinh" };
    can[4] = { name: "Mậu" };
    can[5] = { name: "Kỷ" };
    can[6] = { name: "Canh" };
    can[7] = { name: "Tân" };
    can[8] = { name: "Nhâm" };
    can[9] = { name: "Quý" };

    this.container = null;
    var btnStart = null;
    var tableChi = null;
    var tableCan = null;

    var fillQuestion = function (input, number)
    {
        var snumber = (number + "");
        this.container.find("[" + input + "]").each(function (index)
        {
            var value = snumber.charAt(index);
            if (value != "") $(this).removeClass("hide").find("span").html("?");
        });
    }
    var fillNumber = function (input, number, onFill)
    {
        var snumber = (number + "");
        this.container.find("[" + input + "]").each(function (index)
        {
            var value = snumber.charAt(index);
            if (value != "")
            {
                var span = $(this).removeClass("hide").find("span");
                span.html(value);
                if (onFill != null) onFill(span, snumber.length, index);
            }
        });
    }
    var balance = function (step, left, right)
    {
        var totalLeft = 5 - left;
        var totalRight = 4 - right;

        var area = this.container.find("[data-step=" + step + "] ul");

        for (var i = 1; i <= totalLeft; i++)
        {
            var liEmpty = $("<li class='page-item m-1' data-empty='" + step + "'><span class='page-link xs-page-link rounded-0 border-0 bg-white'> </span></li>");
            area.prepend(liEmpty);
        }
        for (var i = 1; i <= totalRight; i++)
        {
            var liEmpty = $("<li class='page-item m-1' data-empty='" + step + "'><span class='page-link xs-page-link rounded-0 border-0 bg-white'> </span></li>");
            area.append(liEmpty);
        }
    }

    this.start = function ()
    {
        var $this = this;
        buildTable(tableChi = this.container.find("[data-form=table-chi] tbody"), chi);
        buildTable(tableCan = this.container.find("[data-form=table-can] tbody"), can);

        this.container.find(".n-input").each(function ()
        {
            $(this).inputKeypress(function (input)
            {
                if (input.val().length >= 1) input.next(".n-input").setFocus();
                stop.bind($this)();
                clear.bind($this)();
            }, {
                onBackspaceEmpty: function (input) {
                    input.prev(".n-input").setFocus();
                    stop.bind($this)();
                    clear.bind($this)();
                },
                onNoChange: function (input) 
                {
                    input.next(".n-input").setFocus();
                    stop.bind($this)();
                    clear.bind($this)();
                }
            });
        });

        btnStart = this.container.find("[data-btn=Start]");
        btnStart.click(function ()
        {
            if (btnStart.state == null) btnStart.state = 0;
            if (btnStart.state == 0)
            {
                btnStart.state = 1;
                run.bind($this)();
                btnStart.html("Dừng tính toán");
            }
            else stop.bind(this)();
        });

        this.container.find("#inputSpeed").change(function () { interval = parseInt($(this).attr("max")) - parseInt($(this).val()); });
    }

    var interval = 1200;
    var timer;

    var clearHelper = function (area)
    {
        area.find("li[data-type=number]").find("span").html("?");
        area.find("[data-need-hide=true]").addClass("hide");
    }
    var clearResult = function ()
    {
        tableCan.find("td").removeClass("bg-danger bg-success text-white");
        tableChi.find("td").removeClass("bg-danger bg-success text-white");
        this.container.find("[data-need-clear-css]").find("span").removeClass("bg-crimson text-white bg-info bg-dark bg-sienna");
        this.container.find("[data-empty]").remove();
        return this.container.find(".n-input-result").val("_");
    };
    var runChoose = function (table, dataItem, css)
    {
        table.find("td").removeClass("bg-danger bg-success text-white");
        dataItem.element.td1.addClass(css + " text-white");
    }
    var runChooseResult = function (table, data, number, name)
    {
        var $this = this;
        Enumerable.From(data).Where(function (c) { return c.Key <= number; }).ForEach(function (c)
        {
            scripts.push(function () { runChoose(table, c.Value, "bg-danger"); });
            if (c.Key == number) {
                scripts.push(function () { runChoose(table, c.Value, "bg-success"); });
                scripts.push(function () { $this.container.find("[name=" + name + "]").val(c.Value.name); });
            }
        });
    }

    var clear = function ()
    {
        clearHelper.bind(this)(this.container);
        clearResult.bind(this)();
    }

    var run = function ()
    {
        clear.bind(this)();

        scripts = [];
        
        if (timer != null) timer.stop();
        if (timer == null)
        {
            timer = new Core.Timer({ interval: function () { return interval; } });
            timer.onStop = function ()
            {                        
                btnStart.state = 0;
                btnStart.html("Thực hiện tính năm âm lịch");
            };
        }

        onCreateScripts.bind(this)(scripts);

        var scriptIndex = 0;
        timer.setOption(function (options)
        {
            options.onTick = function ()
            {
                scripts[scriptIndex]();
                scriptIndex++;
            };
            options.stopWhen = function () { return scriptIndex == scripts.length; };
        });
        timer.start();
    }
    var stop = function ()
    {
        if (timer == null) return;
        timer.stop();
        timer.onStop();
    }

    var onCreateScripts = function (scripts)
    {
        var year = Enumerable.From(this.container.find(".n-input")).ToString("", function (input) { return $(input).val(); });
        if (year.length < 4)
        {
            Core.alert("Vui lòng nhập năm dương lịch từ 1900 tới nay");
            return;
        }
        year = parseInt(year);
        var $this = this;

        // Tính Can
        var endNumberOfYear = parseInt((year + "").charAt(3));
        var endNumberOfYearExtend6 = endNumberOfYear + 6;

        scripts.push(function ()
        {
            balance.bind($this)("3", 3, 2);
            fillQuestion.bind($this)("data-step-3-input-1", endNumberOfYear);
            fillQuestion.bind($this)("data-step-3-result", endNumberOfYearExtend6 < 10 ? "0" + endNumberOfYearExtend6 : endNumberOfYearExtend6);
            $this.container.find("[data-step=3]").removeClass("hide");
        });
        scripts.push(function () { fillNumber.bind($this)("data-step-3-input-1", endNumberOfYear); });
        scripts.push(function () { fillNumber.bind($this)("data-step-3-result", endNumberOfYearExtend6 < 10 ? "0" + endNumberOfYearExtend6 : endNumberOfYearExtend6); });

        var end_endNumberOfYearExtend6 = (endNumberOfYearExtend6 + "").charAt(((endNumberOfYearExtend6 + "")).length - 1);
        runChooseResult.bind($this)(tableCan, can, end_endNumberOfYearExtend6, "can");

        // Tính chi

        scripts.push(function ()
        {
            balance.bind($this)("1", 4, 4);
            $this.container.find("[data-step=1]").removeClass("hide");
        });
        scripts.push(function () { fillNumber.bind($this)("data-step-1-input-1", year); });

        var yearShort = parseInt((year + "").charAt(2) + (year + "").charAt(3)); 
        if (year < 2000)                
            scripts.push(function () { $this.container.find("[data-step-1=compare]").html("").append('<i class="fa fa-angle-left font-weight-bolder"></i>') });                
        else
        {                    
            scripts.push(function () { $this.container.find("[data-step-1=compare]").html("").append('<i class="fa fa-angle-right font-weight-bolder"></i>') });
            var yearShortExtend = yearShort + 4;
            var yearShortTemp = yearShort;

            scripts.push(function ()
            {
                balance.bind($this)("11", 4, 2);
                fillQuestion.bind($this)("data-step-11-input-1", yearShortTemp < 10 ? "0" + yearShortTemp : yearShortTemp);
                fillQuestion.bind($this)("data-step-11-result", yearShortExtend < 10 ? "0" + yearShortExtend : yearShortExtend);
                $this.container.find("[data-step=11]").removeClass("hide");
            });
            
            scripts.push(function () { fillNumber.bind($this)("data-step-11-input-1", yearShortTemp < 10 ? "0" + yearShortTemp : yearShortTemp); });
            scripts.push(function () { fillNumber.bind($this)("data-step-11-result", yearShortExtend < 10 ? "0" + yearShortExtend : yearShortExtend); });

            yearShort = yearShortExtend;
        }

        var yearShortDiv12 = parseInt(yearShort / 12);
        var yearShortDiv12Remainder = yearShort % 12;

        scripts.push(function ()
        {
            balance.bind($this)("2", 5, (yearShortDiv12Remainder + "").length + 2);
            fillQuestion.bind($this)("data-step-2-input-1", yearShort < 10 ? "0" + yearShort : yearShort);
            fillQuestion.bind($this)("data-step-21-result", yearShortDiv12);
            fillQuestion.bind($this)("data-step-22-result", yearShortDiv12Remainder);

            if (year < 2000)
            {
                $this.container.find("[data-step-2-input-1=0]").find("span").addClass("bg-crimson text-white");
                $this.container.find("[data-step-2-input-1=1]").find("span").addClass("bg-info text-white");
            }
            else $this.container.find("[data-step-2-input-1]").find("span").addClass("bg-sienna text-white");

            $this.container.find("[data-step=2]").removeClass("hide");
        });
        scripts.push(function () { fillNumber.bind($this)("data-step-2-input-1", yearShort < 10 ? "0" + yearShort : yearShort); });
        scripts.push(function () { fillNumber.bind($this)("data-step-21-result", yearShortDiv12); });
        scripts.push(function () { fillNumber.bind($this)("data-step-22-result", yearShortDiv12Remainder); });

        runChooseResult.bind($this)(tableChi, chi, yearShortDiv12Remainder, "chi");
    }

    var buildTable = function (table, data)
    {
        Enumerable.From(data).ForEach(function (c)
        {
            var tr = $("<tr>");
            var td1 = $("<td class='text-center'>"); tr.append(td1); td1.html(c.Key);
            var td2 = $("<td>"); tr.append(td2); td2.html(c.Value.name);
            table.append(tr);
            c.Value.element = { tr, td1, td2 };
        });
    }
}

var calculator = new CalculatorLunarCalendar();
calculator.container = $("article");
calculator.start();
2. Code Html
<div class="row">
    <div class="col-sm-8">
        <div class="row mb-2">
            <div class="col-12 mb-2">
                <h6>Hãy nhập năm (1900 - nay) muốn tính năm âm lịch</h6>
            </div>
            <div class="col-12 text-center mb-3">
                <input type="text" class="form-control text-center n-input d-inline number" maxlength="1" value="1" />
                <input type="text" class="form-control text-center n-input d-inline number" maxlength="1" value="9" />
                <input type="text" class="form-control text-center n-input d-inline number" maxlength="1" value="8" />
                <input type="text" class="form-control text-center n-input d-inline number" maxlength="1" value="3" />
                <input type="text" class="form-control text-center n-e d-inline border-0" maxlength="1" value="=" />
                <input type="text" class="form-control text-center n-input-result d-inline" maxlength="1" value="_" readonly="readonly" name="can" />
                <input type="text" class="form-control text-center n-input-result d-inline" maxlength="1" value="_" readonly="readonly" name="chi" />
            </div>
            <div class="col-12">
                <div class="form-group mb-2">
                    <input class="form-control-range" id="inputSpeed" name="Length" value="600" min="500" max="2000" type="range" />
                </div>
            </div>
            <div class="col-12 text-center">
                <a class="btn btn-primary text-white ml-2" data-btn="Start">Thực hiện tính năm âm lịch</a>
            </div>
        </div>

        <div class="row">
            <div class='col-sm-12 web-pagination hide' data-step="3" data-need-hide="true">
                <h6>Bước 1: Chúng ta đi tìm Can</h6>
            </div>
            <div class='col-sm-12 web-pagination hide' data-step="3" data-need-hide="true">
                <ul class='pagination justify-content-center'>
                    <li class='page-item m-1' data-type="number" data-step-3-input-1="0"><span class='page-link xs-page-link rounded-0 bg-info text-white'>?</span></li>
                    <li class='page-item m-1 hide' data-type="number" data-step-3-input-1="1"><span class='page-link xs-page-link rounded-0'>?</span></li>
                    <li class='page-item m-1 m-0 mt-1 mb-1'>
                        <span class='page-link xs-page-link rounded-0 border-0 color-black font-weight-bold' style="min-width:37px;"><b>+</b></span>
                    </li>
                    <li class='page-item m-1' data-step-3-input-2="0"><span class='page-link xs-page-link rounded-0'>6</span></li>
                    <li class='page-item m-1 m-0 mt-1 mb-1'>
                        <span class='page-link xs-page-link rounded-0 border-0 color-black' style="min-width:37px;"><i class='fa fa-pause fa-rotate-90'></i></span>
                    </li>
                    <li class='page-item m-1' data-type="number" data-step-3-result="0"><span class='page-link xs-page-link rounded-0'>?</span></li>
                    <li class='page-item m-1' data-type="number" data-step-3-result="1" data-need-hide="true"><span class='page-link xs-page-link rounded-0 bg-mediumvioletred text-white'>?</span></li>
                </ul>
            </div>

            <div class='col-sm-12 web-pagination hide' data-step="1" data-need-hide="true">
                <h6>Bước 2: Chúng ta đi tìm chi</h6>
            </div>
            <div class='col-sm-12 web-pagination hide' data-step="1" data-need-hide="true">
                <ul class='pagination justify-content-center'>
                    <li class='page-item m-1' data-type="number" data-step-1-input-1="0"><span class='page-link xs-page-link rounded-0'>?</span></li>
                    <li class='page-item m-1' data-type="number" data-step-1-input-1="1"><span class='page-link xs-page-link rounded-0'>?</span></li>
                    <li class='page-item m-1' data-type="number" data-step-1-input-1="2"><span class='page-link xs-page-link rounded-0 bg-crimson text-white'>?</span></li>
                    <li class='page-item m-1' data-type="number" data-step-1-input-1="3"><span class='page-link xs-page-link rounded-0 bg-info text-white'>?</span></li>
                    <li class='page-item m-1 m-0 mt-1 mb-1' data-type="number">
                        <span class='page-link xs-page-link rounded-0 border-0 color-black font-weight-bold' data-step-1="compare" style="min-width:37px;">?</span>
                    </li>
                    <li class='page-item m-1' data-step-1-input-2="0"><span class='page-link xs-page-link rounded-0'>2</span></li>
                    <li class='page-item m-1' data-step-1-input-2="1"><span class='page-link xs-page-link rounded-0'>0</span></li>
                    <li class='page-item m-1' data-step-1-input-2="2"><span class='page-link xs-page-link rounded-0'>0</span></li>
                    <li class='page-item m-1' data-step-1-input-2="3"><span class='page-link xs-page-link rounded-0'>0</span></li>
                </ul>
            </div>
            <div class='col-sm-12 web-pagination hide' data-step="11" data-need-hide="true">
                <ul class='pagination justify-content-center'>
                    <li class='page-item m-1' data-type="number" data-step-11-input-1="0"><span class='page-link xs-page-link rounded-0 bg-crimson text-white'>?</span></li>
                    <li class='page-item m-1 hide' data-type="number" data-step-11-input-1="1"><span class='page-link xs-page-link rounded-0 bg-info text-white'>?</span></li>
                    <li class='page-item m-1 m-0 mt-1 mb-1'>
                        <span class='page-link xs-page-link rounded-0 border-0 color-black font-weight-bold' style="min-width:37px;"><b>+</b></span>
                    </li>
                    <li class='page-item m-1' data-step-11-input-2="0"><span class='page-link xs-page-link rounded-0'>4</span></li>
                    <li class='page-item m-1 m-0 mt-1 mb-1'>
                        <span class='page-link xs-page-link rounded-0 border-0 color-black' style="min-width:37px;"><i class='fa fa-pause fa-rotate-90'></i></span>
                    </li>
                    <li class='page-item m-1' data-type="number" data-step-11-result="0"><span class='page-link xs-page-link rounded-0 bg-sienna text-white'>?</span></li>
                    <li class='page-item m-1 hide' data-type="number" data-step-11-result="1" data-need-hide="true"><span class='page-link xs-page-link rounded-0 bg-sienna text-white'>?</span></li>
                </ul>
            </div>
            <div class='col-sm-12 web-pagination hide' data-step="2" data-need-hide="true">
                <ul class='pagination justify-content-center'>
                    <li class='page-item m-1' data-type="number" data-step-2-input-1="0" data-need-clear-css="true"><span class='page-link xs-page-link rounded-0'>?</span></li>
                    <li class='page-item m-1 hide' data-type="number" data-step-2-input-1="1" data-need-clear-css="true"><span class='page-link xs-page-link rounded-0'>?</span></li>
                    <li class='page-item m-1 m-0 mt-1 mb-1'>
                        <span class='page-link xs-page-link rounded-0 border-0 color-black font-weight-bold' style="min-width:37px;"><b>:</b></span>
                    </li>
                    <li class='page-item m-1' data-step-2-input-2="0"><span class='page-link xs-page-link rounded-0'>1</span></li>
                    <li class='page-item m-1' data-step-2-input-2="1"><span class='page-link xs-page-link rounded-0'>2</span></li>
                    <li class='page-item m-1 m-0 mt-1 mb-1'>
                        <span class='page-link xs-page-link rounded-0 border-0 color-black' style="min-width:37px;"><i class='fa fa-pause fa-rotate-90'></i></span>
                    </li>
                    <li class='page-item m-1' data-type="number" data-step-21-result="0"><span class='page-link xs-page-link rounded-0'>?</span></li>
                    <li class='page-item m-1 hide' data-type="number" data-step-21-result="1"><span class='page-link xs-page-link rounded-0'>?</span></li>
                    <li class='page-item m-1 m-0 mt-1 mb-1'>
                        <span class='page-link xs-page-link rounded-0 border-0 color-black font-weight-bold' style="min-width:37px;">Dư</span>
                    </li>
                    <li class='page-item m-1' data-type="number" data-step-22-result="0"><span class='page-link xs-page-link rounded-0 bg-indianred text-white'>?</span></li>
                    <li class='page-item m-1 hide' data-type="number" data-step-22-result="1" data-need-hide="true"><span class='page-link xs-page-link rounded-0 bg-indianred text-white'>?</span></li>
                </ul>
            </div>
        </div>
    </div>
    <div class="col-sm-2">
        <table class="table table-bordered table-striped table-sm" data-form="table-can">
            <thead>
                <tr>
                    <th class="text-center align-middle">Stt</th>
                    <th class="text-center align-middle">Can</th>
                </tr>
            </thead>
            <tbody></tbody>
        </table>
    </div>
    <div class="col-sm-2">
        <table class="table table-bordered table-striped table-sm" data-form="table-chi">
            <thead>
                <tr>
                    <th class="text-center align-middle">Stt</th>
                    <th class="text-center align-middle">Chi</th>
                </tr>
            </thead>
            <tbody></tbody>
        </table>
    </div>    
</div>

Sơn 20