问题描述
我正在使用JFreeChart库创建一个烛台图.我需要将时间值传递给OHLCSeries,但它只接受自己的时间值
I'm creating a candlestick chart using the JFreeChart library. I need to pass time values into OHLCSeries, but it only accepts its own time values
我将通过此类 https://www.jfree.org/jfreechart/api/javadoc/org/jfree/data/time/Hour.html
这个构造函数:Hour(int hour,int day,int month,int year)
And this constructor: Hour(int hour, int day, int month, int year)
我从API获得的数据最初看起来像这样:2021-03-02T16:00:00.000Z
The data which I get from the API originally looks like this: 2021-03-02T16:00:00.000Z
我的问题:如何将此日期字符串/Java时间格式转换为JFreeChart的Date格式?我只能考虑一些复杂的转换成Java类型+分别返回每个值,或使用正则表达式
My question: how to convert this date string/Java time formats into JFreeChart's Date format? I can only think about some complicated converting into Java types + returning each value separately, or using regexes
推荐答案
您可以解析将日期时间字符串解析为 即时
,然后获取 java.util.Date
对象从这一刻起.使用此 java.util.Date
对象,您可以创建"> 小时
.
You can parse the date-time string into Instant
and then get java.util.Date
object from this instant. Using this java.util.Date
object, you can create an instance of Hour
.
String strDateTime = "2021-03-02T16:00:00.000Z";
Instant instant = Instant.parse(strDateTime);
Hour hour = new Hour(Date.from(instant)));
这篇关于如何将Java的日期字符串/对象转换为JFreeChart的Date格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!