gpt4 book ai didi

java - 儒略日期转换

转载 作者:行者123 更新时间:2023-12-02 01:06:03 24 4
gpt4 key购买 nike

Sample Julian Dates:
2009218
2009225
2009243

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

我尝试使用 online converter 转换它们我得到了-

12-13-7359 2009225!!毫无意义!

最佳答案

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

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:

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 提供最佳答案:

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

关于java - 儒略日期转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3036761/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com