问题
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