There are a couple things you could mean by the time of the transaction:
- When the transaction is created
- When the transaction is known about by 90% of the network
- When the transaction is first included into a block
- When the block is known to 90% of the network
We can't know 1, because it could have been generated offline, and there's no time field. You can assume that 1 is 30 seconds or so before 2, but again, you can't know.
We can figure out 2, because the time that we receive the transaction is going to be pretty much the same as when 90% of the network does. For historical data, blockchain.info has an API.
We can figure out 3, because there's a time field in the block. However, that can be off by up to an hour, and the network won't care. Still, there's not much reason to lie about it.
Figuring out 4 is pretty much the same as 2.