如何将Java的日期字符串/对象转换为JFreeChart的Date格式? [英] How to convert Java's date strings/objects into JFreeChart's Date format?

查看:65
本文介绍了如何将Java的日期字符串/对象转换为JFreeChart的Date格式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用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

推荐答案

您可以 小时 .

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格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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