How can I convert a string to RegularTimePeriod in java?
I am using Jfreechart. I have code like this:
TimeSeries t1 = new TimeSeries("EUR/GBP");
t1.add(new Day(4, MonthConstants.JANUARY, 2001), new Double(1.5807));
But I am getting String
from my SQL query. TimeSeries only accepts RegularTimePeriod
or TimeSeriesDataItem
.
Please let me know how to convert String
to RegularTimePeriod
.
Thanks in Advance.
0
source to share
1 answer
You can first get a Date object by parsing a mysql date string with SimpleDateFormat, and then create your RegularTimePeriod using a constructor with a Date argument.
Basically (assuming mysqlDateStr is your string from a mysql query):
SimpleDateFormat standardDateFormat = new SimpleDateFormat("yyyy-MM-dd");
// (Define your formatter only once, then reuse)
Date myDate = standardDateFormat.parse(mysqlDateStr);
// (you may want to catch a ParseException)
t1.add(new Day(myDate), new Double(1.5807));
+3
source to share