1

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.

Edit

I need a Date object that gives back the exact time up to the millisecond accurate.

Does .getStart() provide this?

[ANSWER]: YES

Jean-Paul
  • 19,910
  • 9
  • 62
  • 88

3 Answers3

2

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.

azurefrog
  • 10,785
  • 7
  • 42
  • 56
  • so `.getStart()` will give me the exact date up to the millisecond I put in? (I'm working with millisecond data so this is crucial to know for me). And `.getEnd()` will give me the **next** millisecond? – Jean-Paul Mar 20 '14 at 23:28
  • 1
    No, it's still the same millisecond, since it only has millisecond precision. I added a snippet to my answer to demonstrate. – azurefrog Mar 20 '14 at 23:33
1

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.

Kai Huppmann
  • 10,705
  • 6
  • 47
  • 78
0

(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.

Whome
  • 10,181
  • 6
  • 53
  • 65