Code Monkey home page Code Monkey logo

calendarist's Introduction

历法计算家,可实现阳历、阴历、干支历的相互转换

maven license

使用方法

Maven引用

<dependency>
    <groupId>org.hothub</groupId>
    <artifactId>calendarist</artifactId>
    <version>1.0.7</version>
</dependency>

功能介绍

  1. 支持1900 - 2100年份的日期转换
  2. 支持阳历日期转阴历日期
  3. 支持阴历日期转阳历日期
  4. 支持阳历日期转干支日期
  5. 支持阴历日期转干支日期

参数/字段说明

字段 说明 类型 取值范围 适用
YEAR int 1900 - 2100 阳历&阴历
MONTH int 1 - 12 阳历&阴历
DAY_OF_MONTH int 1 - 31 阳历&阴历
HOUR_OF_DAY int 0 - 23 阳历&阴历
MINUTE int 0 - 59 阳历&阴历
SECOND int 0 - 59 阳历&阴历
MILLISECOND 毫秒 int 0 - 999 阳历&阴历
LEAP_MONTH_OF_CURRENT 指定月是否是闰月 boolean true / false 阴历

代码示例:

阳历转阴历、干支历:

//设置要转换的阳历日期
Calendarist calendarist = Calendarist.fromSolar(2020, 1, 1, 12, 15, 55, 58);

//转阴历
LunarDate lunarDate = calendarist.toLunar();
//转阳历
SolarDate solarDate = calendarist.toSolar();
//转干支历
CycleDate cycleDate = calendarist.toCycle();

阴历转阳历、干支历:

//设置要转换的阴历日期,且需设置指定月是否是闰月及指定年的闰月月份
Calendarist calendarist = Calendarist.fromLunar(2020, 1, 1, 12, 15, 55, 580, false);

//转阴历
LunarDate lunarDate = calendarist.toLunar();
//转阳历
SolarDate solarDate = calendarist.toSolar();
//转干支历
CycleDate cycleDate = calendarist.toCycle();

其他用法:

阳历转阴历、干支历:

//设置要转换的阳历日期
Calendarist calendarist = Calendarist.fromSolar(2020, 1, 1);
calendarist.set(Calendarist.HOUR, 12);
calendarist.set(Calendarist.MINUTE, 15);
calendarist.set(Calendarist.SECOND, 55);
calendarist.set(Calendarist.MILLISECOND, 58);

//转阴历
LunarDate lunarDate = calendarist.toLunar();
//转阳历
SolarDate solarDate = calendarist.toSolar();
//转干支历
CycleDate cycleDate = calendarist.toCycle();

阴历转阳历、干支历:

//设置要转换的阴历日期,且需设置指定月是否是闰月及指定年的闰月月份
Calendarist calendarist = Calendarist.fromLunar(2020, 1, 1, 12, 15, 55, 58);
calendarist.set(Calendarist.HOUR, 12);
calendarist.set(Calendarist.MINUTE, 15);
calendarist.set(Calendarist.SECOND, 55);
calendarist.set(Calendarist.MILLISECOND, 58);
//从阴历转换时,要指定当前月是否是闰月,建议使用第一种方式
方式一,当值为false时表示指定月非闰月,为true时表示指定月是闰月,默认为false:
calendarist.itsLeapMonth(true);
方式二,当值为0时表示指定月非闰月,为1时表示指定月是闰月,默认为0:
calendarist.set(Calendarist.LEAP_MONTH_OF_CURRENT, 1);

//转阴历
LunarDate lunarDate = calendarist.toLunar();
//转阳历
SolarDate solarDate = calendarist.toSolar();
//转干支历
CycleDate cycleDate = calendarist.toCycle();

calendarist's People

Contributors

opprime avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.