Java - Convert OffsetDateTime/ timestamp to RegularTimePeriod to plot time series graph (Jfreechart)

落花浮王杯 提交于 2020-01-25 06:57:12

问题


I currently trying to plot a graph using Jfreechart, and it accept only RegularTimePeriod

My date String is: zzz ***Wed Jan 15 10:00:03 +08 2020

From this Question I learned to parse such a string into an OffsetDateTime object. By calling OffsetDateTime I get this string:

2020-01-15T10:00:03+08:00

Then I was trying to make it into RegularTimePeriod, specifically "second". I'm lost and confused about the conversion.

Here is my code:

TimeSeries s1 = new TimeSeries("Something");

DateTimeFormatter f = DateTimeFormatter.ofPattern( "'zzz ***'EEE MMM dd HH:mm:ss x uuuu" ).withLocale( Locale.US );
OffsetDateTime moment = OffsetDateTime.parse( "zzz ***Wed Jan 15 10:00:03 +08 2020" , f );
Timestamp timestamp =Timestamp.valueOf(LocalDateTime.ofInstant(moment.toInstant(), ZoneOffset.UTC));

s1.add(timestamp,value);

error: Timestamp cannot be converted to RegularTimePeriod

Javadoc from JFree project:

  • RegularTimePeriod
  • TimeSeries

来源:https://stackoverflow.com/questions/59766445/java-convert-offsetdatetime-timestamp-to-regulartimeperiod-to-plot-time-serie

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!