Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lunar阳历日期转换出错,算法不对 #21

Open
a316375 opened this issue Jul 31, 2022 · 4 comments
Open

Lunar阳历日期转换出错,算法不对 #21

a316375 opened this issue Jul 31, 2022 · 4 comments

Comments

@a316375
Copy link

a316375 commented Jul 31, 2022

我明明设置一个【1986-9-1 00:02:02 】的数据,并且转换成为一个13位的时间戳, 根据时间戳导入后-转换后竟然变成【1986-08-31 23:02:02 】

这个时间戳计算差了1天,连日期都改变了 //实测 Andriod Java 运行日期计算错误,时间戳转换日期出错

//设置一个1986-9-1 的数据
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.YEAR,1986);
calendar.set(Calendar.MONTH,8);
calendar.set(Calendar.DAY_OF_MONTH,1);
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.MINUTE, 2);
calendar.set(Calendar.SECOND, 2);

                 //SimpleDateFormat来输出规范的字符串 拿到时间戳
                        SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日");
                        sdf.setTimeZone(TimeZone.getTimeZone("Asia/Shanghai"));  //上海,对应正八区
                        String format = sdf.format(calendar.getTime());//拿到时间戳
                        System.out.println("Calendar 1986-9-1 转换后时间戳"+format+calendar.getTime().getTime() );

                     
                        System.out.println("Lunar阳历日期:"+ Solar.fromDate(new Date(calendar.getTime().getTime())).getLunar().getSolar().toFullString());

打印结果
Lunar阳历日期:1986-08-31 23:02:02 星期日 处女座
我明明设置一个【1986-9-1 00:02:02 】的数据,并且转换成为一个时间戳, 导入后-转换后竟然变成【1986-08-31 23:02:02 】

@6tail
Copy link
Owner

6tail commented Aug 4, 2022

Calendar要设置时区。

@xuanyunhui
Copy link

xuanyunhui commented Aug 5, 2022

public static Solar fromCalendar(Calendar calendar) {

用这个方法不就不用转换了

@6tail
Copy link
Owner

6tail commented Nov 8, 2022

Calendar和Date都需要注意时区。

@patience00
Copy link

刚开始我也以为不对, 翻看了文档才发现是自己使用方法有问题, 目前验证出来的都没有问题, 我只能说大佬太牛皮了, 请收下我的膝盖, 这些质疑有错误的issues我觉得可以关了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants