I am trying to do a simple epoch to date conversion using SimpleDateFormat. Whenever I run the program, I keep receiving invalid dates post-conversion. I have run the epoch stamps in a converter [and I also have the dates stored in an outside server], so I know what the output should be, but I am still receiving bad conversions. I have tried multiple mathematical changes to the long epochTime in experimenting, but to no avail. I do know [or at least am mostly sure] that my epoch timestamp is stored in milliseconds, thus requiring a * 1000 change. Here is what I have:
String convertedTime = null;
//(1) //startTime = startTime/1000; --none of these three manipulations solve the issue
//(2) //startTime = startTime * 1000;
//(3) //long change = (long) startTime * 1000;
Date d = newDate(startTime); //startTime is *long* parameter passed into method
SimpleDateFormat formatter = new SimpleDateFormat("mm-dd-yyyy 'at' hh:mm:ss");
convertedTime= formatter.format(d);
For example, if the epoch stamp is 1404327407738 and I do not include (1), (2), (3) I receive 56-02-2014 at 01:56:47 PM
I should receive 07-02-2014 at 01:56:47 PM
The format string should be "MM-dd-yyyy 'at' hh:mm:ss".
"MM" is for the month in year, "mm" is for the minutes in hour (see http://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html).