Reputation: 21150
Regarding jFreeChart's Millisecond,
How can I get a java.util.Date object from a Millisecond
instance?
From the docs, it only seems possible to subtract the milliseconds within Millisecond
.
Since a Millisecond
object is constructed like so:
Millisecond ms = new Millisecond(
millisec,
second,
minute,
hour,
day,
month,
year);
I should be able to extract a valid Date
object as well.
I need a Date
object that gives back the exact time up to the millisecond accurate.
Does .getStart()
provide this?
[ANSWER]: YES
Upvotes: 1
Views: 419
Reputation: 10400
(my answer was late) Perhaps you could use this code:
java.util.Date date = new java.util.Date(freeMillis.getMillisecond());
edit: scrap that, freeMillis.getMillisecond() returns just a millisecond part.
Upvotes: 0
Reputation: 10945
Millisecond is like any other RegularTimePeriod in JFreeChart, so you can just
Date d = ms.getStart();
or
Date d = ms.getEnd();
depending on whether you want a date referring to the beginning or the end of your millisecond (same value either way).
See The JFreeChart API for more info.
EDIT: Adding code here since comments kill formatting:
Millisecond ms = new Millisecond();
System.out.println(ms.getStart().getTime());
System.out.println(ms.getEnd().getTime());
will print the same millisecond twice.
Upvotes: 2
Reputation: 10775
As far as I can see the Millisecond
Class represents the time period of a millisecond and I'd assume the the getStart
and getEnd
Methods inherited from RegularTimePeriod
return (nearly) the same Date
of which one is one you're looking for.
Upvotes: 1