朱利安日期转换 [英] Julian Date Conversion

查看:312
本文介绍了朱利安日期转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Sample Julian Dates:
2009218
2009225
2009243

如何将它们转换为常规日期?

How do I convert them into a regular date?

我尝试使用在线转换器我得到了 -

I tried converting them using online converter and I got-

12-13-7359 for 2009225 !!没有意义!

12-13-7359 for 2009225!! Makes no sense!

推荐答案

使用 Joda-Time 库并执行以下操作:

Use the Joda-Time library and do something like this:

String dateStr = "2009218";
MutableDateTime mdt = new MutableDateTime();
mdt.setYear(Integer.parseInt(dateStr.subString(0,3)));
mdt.setDayOfYear(Integer.parseInt(dateStr.subString(4)));
Date parsedDate  = mdt.toDate();

使用Java API:

Using the Java API:

String dateStr = "2009218";
Calendar cal  = new GregorianCalendar();
cal.set(Calendar.YEAR,Integer.parseInt(dateStr.subString(0,3)));
cal.set(Calendar.DAY_OF_YEAR,Integer.parseInt(dateStr.subString(4)));
Date parsedDate  = cal.getTime();

----编辑----
感谢Alex提供最佳答案:

---- EDIT ---- Thanks for Alex for providing the best answer:

Date myDate = new SimpleDateFormat("yyyyD").parse("2009218")

这篇关于朱利安日期转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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