I see that this is deprecated in Java:
Date origin = new Date("July 5, 2318 12:00:00");
What I'm trying to figure out is what I can do to get that exact same functionality. The full context of my example is this:
Date origin = new Date("July 5, 2318 12:00:00");
double stardatesPerYear = 56844.9 * 34367056.4;
double milliseconds = origin.getTime() + stardatesPerYear;
Date dateResult = new Date();
dateResult.setTime((long)milliseconds);
The result of that is that dateResult
will a Date object with the following string representation:
Sat May 31 12:24:44 CDT 2380
I'm not concerned about the exact format of the date as I am the accuracy of the result as well as the fact that it can be parsed.
I've seen references to using Calendar
and SimpleDateFormat
but none of those seem to get me the same output, likely because I'm doing something wrong.
UPDATE ON POSSIBLE DUPLICATE:
I don't know if my question is a duplicate as suggested, but it may be. I tried some examples like this:
String string = "July 5, 2318";
DateFormat format = new SimpleDateFormat("MMMM d, yyyy", Locale.ENGLISH);
try {
Date date = format.parse(string);
} catch (ParseException e) {
e.printStackTrace();
}
That seems like a lot to replace my original Date origin
statement.
I guess what I'm curious about is given my full code example, which is this:
Date origin = new Date("July 5, 2318 12:00:00");
double stardatesPerYear = 56844.9 * 34367056.4;
double milliseconds = origin.getTime() + stardatesPerYear;
Date dateResult = new Date();
dateResult.setTime((long)milliseconds);
What's the most effective and efficient code to replace the first line of that code, since it is indicated to me that my first line is using deprecated functionality?