Home
Analytics
how do I convert milliseconds to date/time ?
c031917
I have a dataset row containing milliseconds since midnight January 1, 1970,
e.g. 1238158558269
I tried
x = new Packages.java.util.Date();
x.setTime(dataSetRow["C_TIME"]);
to display a normal date and time.
But this gives me an empty field. And only using the first line shows me the current date, not midnight January 1, 1970. So adding 1238158558269
would not yield the correct timestamp.
What's wrong ?
Peter
Find more posts tagged with
Comments
mwilliams
Hi Peter,
You can do that by creating a computed column in your dataSet of type "date time" with the following expression:
new Date(1970,0,1,0,0,0,row["milliseconds"]);
Hope this helps.
c031917
Hi Michael,
yes, you helped me - again!!
When I put this into the expression builder for the bound column:
x = new Date(1970,0,1,0,0,0,dataSetRow["C_TIME"]);
it works perfectly. I'm not sure why "x =" is necessary but i get my timestamps displayed..
Thank You very much
Peter
mwilliams
Peter,
No problem. Glad I could help!
Let us know whenever you have questions.
harmeetsin
<blockquote class='ipsBlockquote' data-author="'mwilliams'" data-cid="45492" data-time="1238182019" data-date="27 March 2009 - 12:26 PM"><p>
Hi Peter,<br />
<br />
<br />
You can do that by creating a computed column in your dataSet of type "date time" with the following expression:<br />
<br />
<br />
new Date(1970,0,1,0,0,0,row["milliseconds"]);<br />
<br />
<br />
Hope this helps.<br /></p></blockquote>
I get 16th Jan 1970 as date using the above expression builder(with time stamp value:1317665700).
mwilliams
That's because your millisecond value is worth about 15.25 days, which with the above expression would give you the date you say it does. So, if your timestamp is from the beginning of the year, rather than from Jan 1, 1970, you'll want to use this year in your new Date() call instead of 1970. Hope this helps.