jeraconv(日文纪元名称转换器)是一个将日文纪元转换为西历的转换器。
jeraconv的Python项目详细描述
杰拉科诺夫
jeraconv(日文纪元名称转换器)是一个将日文纪元转换为西历的转换器。
安装
$ pip install jeraconv
用法
日文日历到西文日历
fromjeraconvimportjeraconv# Create J2W class instancej2w=jeraconv.J2W()# ex.1 : General usageprint(j2w.convert('文治6年'))# result (int) 1190# ex.2 : Full-width numbers are also availableprint(j2w.convert('平成31年'))# result (int) 2019# ex.3 : It is also possible to write "1年" as "元年"print(j2w.convert('令和元年'))# result (int) 2019# ex.4 : Returns a ValueError if the era name does not existprint(j2w.convert('牌孫4年'))# result ValueError
西方日历到日本日历。
fromjeraconvimportjeraconv# Create W2J class instancew2j=jeraconv.W2J()# ex.1 : General usageyear=2019month=5day=31print(w2j.convert(year,month,day))# result (str) 令和1年5月31日# ex.2 : When receiving a response in dictionary typeprint(w2j.convert(year,month,day,return_type='dict'))# result (dict) {'era': '令和', 'year': 1, 'month': 5, 'day': 31}# ex.3 : When receiving a response in list typeprint(w2j.convert(year,month,day,return_type='list'))# result (list) ['令和', 1, 5, 31]# ex.4 : When receiving a response in tuple typeprint(w2j.convert(year,month,day,return_type='tuple'))# result (tuple) ('令和', 1, 5, 31)# ex.5 : If the date is omitted, convert the execution dateprint(w2j.convert())