PostgreSQL localtime Function

The PostgreSQL localtime function returns the current system time in the format HH:MM:SS.ssssss.

localtime Syntax

Here is the syntax of the PostgreSQL localtime function:

localtime -> TIME

or

localtime(precision INTEGER) -> TIME

Parameters

precision

Required. An integer indicating the precision of fractional seconds.

Return value

The PostgreSQL localtime function returns the current system time in the format HH:MM:SS.ssssss.

Note that the localtime function returns the time when the transaction start, not the time when the function was executed.

Unlike the current_time function, localtime functions return a time value without time zone.

localtime Examples

This example shows how to use the PostgreSQL localtime function to get the current system time.

SELECT localtime;
    localtime
-----------------
 20:43:04.582222

You can specify the precision of fractional seconds by a parameter. The following example returns a current time value with 2 fractional seconds:

SELECT localtime(2);
  localtime
-------------
 20:43:13.82

The localtime function returns the time when the current transaction started, not the time when the function was executed.

SELECT localtime, pg_sleep(1), localtime;
-[ RECORD 1 ]--------------
localtime | 20:44:55.114938
pg_sleep  |
localtime | 20:44:55.114938

We can see that even though we used the pg_sleep(1) function to pause for 1 second between the two localtime functions, the two localtime functions still returned the same value.