如何将Java中的Julian转换为Date格式的"yyDHH" [英] How to convert Julian to Date in Java for format of "yyDHH"

查看:55
本文介绍了如何将Java中的Julian转换为Date格式的"yyDHH"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

yy = 15(年),D = 150(年月),HH = 10(小时)

yy = 15 (year), D = 150 (day of year), HH = 10 (hour)

 Date myDateWrong = new SimpleDateFormat("yyDHH").parse("1515010");
 Date myDateTrue = new SimpleDateFormat("yyD").parse("15150");

myDateTrue是正确的:2015年5月30日.myDateWrong必须为2015年5月30日10:00:00,但似乎是2015年7月28日18:00:00.这里有什么问题?

myDateTrue is right: 30/05/2015. myDateWrong must be 30/05/2015 10:00:00 but it seem that 28/07/2015 18:00:00. Whats the problem in here?

推荐答案

我想猜到errorDate在月份(如您指定的)中使用了一位数字,然后在小时中使用了其余的数字(花费的时间与原始格式中的其余日期一样).这样就得到了2015年,1月和5010小时.我没有做详细的计算,但是5010小时将给您大约7个月的时间,这将解释您在7月结束的情况.18:00小时可以反映出剩下的时间.

I'm going to guess that the wrongDate took a single digit for the month (as you specified) and then took the rest of the digits for the hour (much as it took the rest of the digits for the julian date from the original format). So you got 2015, January, and 5010 hours. I haven't done the calculations in detail, but 5010 hours would give you roughly 7 months, which would explain ending up in July. 18:00 hours just reflects whatever hours were left over.

因此,您需要将DDD用作儒略日的说明符(不像另一条注释中建议的那样ddd),然后按预期的那样出现.

So you need to use DDD as the specifier for the Julian day (not ddd as suggested in another comment), and then it comes out as expected.

这篇关于如何将Java中的Julian转换为Date格式的"yyDHH"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆