lunar

package module
v0.0.0-...-344c920 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 1, 2018 License: MIT Imports: 6 Imported by: 0

README

Lunar

Go语言实现的阳历阴历转换

安装

go get github.com/superwen/lunar

使用

以下是代码示例:

package main

import (
	"fmt"
	"time"
	"github.com/superwen/lunar"
)

func main()  {
	myLunar1 , err := lunar.SolarTimeToLunar(time.Now().AddDate(0,1,0))
	if err != nil {
		fmt.Println(err.Error())
		return
	}
	fmt.Printf("%#v\n", myLunar1)

	myLunar2 , err := lunar.SolarToLunar(2018, 5,20)
    if err != nil {
    	fmt.Println(err.Error())
    	return
    }
    fmt.Printf("%#v\n", myLunar2)
}

说明:

  • 本阴历支持的最小年份为 1891,最大年份为 2100
  • Lunar 结构的属性有
    • Year 年份 int 如:2018
    • Month 月份(中文)string 如:五月
    • Date 日(中文) string 如:十八
    • Nian 天干地支 int 如:戊戌
    • EMonth 月份(数字) int 如:5
    • EDate 日(数字) int 如: 18
    • Zodiac 生效 string 如:狗

Documentation

Index

Constants

View Source
const (
	MINYEAR int = 1891
	MAXYEAR int = 2100
)

Variables

This section is empty.

Functions

func GetCapitalDateNum

func GetCapitalDateNum(num int) string

*

  • 获取数字的阴历日的叫法
  • @param num 数字
  • @param isMonth 是否是月份的数字

func GetCapitalMonthNum

func GetCapitalMonthNum(num int) string

*

  • 获取阴历月份名称
  • @param num 数字

func GetDaysBetweenSolar

func GetDaysBetweenSolar(cyear int, cmonth int, cdate int, dyear int, dmonth int, ddate int) int

*

  • 计算2个阳历日期之间的天数
  • @param year 阳历年
  • @param cmonth
  • @param cdate
  • @param dmonth 阴历正月对应的阳历月份
  • @param ddate 阴历初一对应的阳历天数

func GetLeapMonth

func GetLeapMonth(year int) int64

*

  • 获取阴历年闰月
  • @param year 年份

func GetLunarMonths

func GetLunarMonths(year int, yearData [4]int64) []int

*

  • 获取阴历每月的天数的数组

func GetLunarYearDays

func GetLunarYearDays(year int, yearDate [4]int64) int

*

  • 获取农历每年的天数

func GetLunarYearMonths

func GetLunarYearMonths(year int, yearData [4]int64) []int

*

  • 获取阴历年每个月的年累计天数

func GetLunarYearName

func GetLunarYearName(year int) string

*

  • 获取阴历年的天干地支

func GetYearData

func GetYearData(year int) [4]int64

*

  • 获取阴历年份数据库

func GetYearZodiac

func GetYearZodiac(year int) string

*

  • 获取阴历年的生肖

func IsLeapYear

func IsLeapYear(year int) bool

* 判断阳历年是否为闰年

Types

type Lunar

type Lunar struct {
	Year   int
	Month  string
	Date   string
	Nian   string
	EMonth int
	EDate  int
	Zodiac string
}

func GetLunarByBetween

func GetLunarByBetween(year int, between int, yearDate [4]int64) (Lunar, error)

*

  • 根据距离正月初一的天数计算阴历日期
  • @param year 阳历年
  • @param between 天数

func SolarTimeToLunar

func SolarTimeToLunar(mytime time.Time) (Lunar, error)

*

  • 将阳历转换为阴历
  • @param mytime 公历时间

func SolarToLunar

func SolarToLunar(year int, month int, date int) (Lunar, error)

*

  • 将阳历转换为阴历
  • @param year 公历-年
  • @param month 公历-月
  • @param date 公历-日

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL