Converting unix or java timestamps (time since the epoch) to real dates with Oracle

A few days ago I made use of a couple Oracle built in functions and it made me happy I didn't have to write a stored proc or some type of mini-app to do it. I needed to parse a timestamp out of a field that was put there by a java program. The timestamp was just the output of System.currentTimeInMillis() and was concatenated onto some other information.

It took a little digging to find out how to convert a epoch style timestamp but here it is:

select new_time( to_date('01011970', 'ddmmyyyy') + 1/24/60/60 * :currenttimeinmillis/1000, 'GMT', 'EDT' ) from dual

Note that I convert the output from GMT to EDT here.

Tags: ,

Leave a Reply

Your email address will not be published. Required fields are marked *