Java - Convert Unix epoch time to date -
i need convert epoch time stamps real date , have used of methods found on stack overflow, give wrong answer.
as example, 1 date "129732384262470907" in epoch time, "mon, 20 jan 6081 05:24:22 gmt" using http://www.epochconverter.com/
however, code generates: "wed dec 24 14:54:05 cst 19179225"
string epochstring = token.substring(0, comma); long epoch = long.parselong(epochstring); date logdate = new date(epoch * 1000); bufferedwriter timewrite = new bufferedwriter(new filewriter(tempfile, true)); timewrite.write(logdate); timewrite.flush(); timewrite.close();
the initial timestamp in miliseconds, in examples saw here supposed multiply 1000.
if don't multiply 1000, get: "mon aug 08 01:14:30 cdt 4113025"
both of wrong.
so have made error?
129732384262470907 in microseconds since epoch if it's meant 6081, need divide 1000 if that's real input.
note epochconverter.com
doesn't handle value - allows enter 129732384262470
treats milliseconds since epoch.
you need multiply 1000 if data seconds since epoch. need know java expects milliseconds since epoch; rest should plain sailing, assuming know input data means.
if provide real data, , it's meant represent, it's going easy fix problems.
Comments
Post a Comment