Alt-O > IRC > Messages.
In the Quit box, put:
$duration($uptime)
You can, of course, include formatting and other text, such as:
I was online for $duration($uptime)
Keep in mind that some networks may not let you show a QUIT message, and some won't let you show it if you haven't been online long enough to prevent spam. So don't try setting this up, connecting to a network, and disconnecting immediately to see if it works.