5

I have UTC time zone set in my PostgreSQL and SELECT NOW() shows me the right date in psql console.

I use PHPStorm for development and its database console for accessing my database, but it uses different time zone (Europe/Moscow, which is the time zone of my Mac), and SELECT NOW() shows me the time in this time zone (and by the way, the date is wrong, because the Europe/Moscow time zone recently changed its offset to +3 from +4).

I have not found any information on how to tell PHPStorm to use the time zone configured in postgresql.conf instead of system's time zone. Is it possible?

Alexander Guz
  • 1,334
  • 12
  • 31

3 Answers3

5

verify your timezone with query

SELECT * FROM pg_timezone_names

now add phpstorm.vmoptions the config off timezone

-Duser.timezone=posix/America/Sao_Paulo

enter image description here

Apply changes, disconect, synchronize and verify whithselect now()

vandersondf
  • 839
  • 1
  • 9
  • 8
1

Well, I've found a solution, but it will affect every time-specific behavior in IDE, e.g. console logs will show datetime in UTC.

The idea is to pass a timezone to VM options. For that we need to modify a file and restart IDE.

For Mac OS X for the latest version of PHPStorm:

cp /Applications/PhpStorm.app/Contents/bin/phpstorm.vmoptions ~/Library/Preferences/PhpStorm2016.1/

Then add -Duser.timezone=UTC to the file, so that it looks something like that:

-Xms128m
-Xmx750m
-XX:MaxPermSize=350m
-XX:ReservedCodeCacheSize=240m
-XX:+UseCompressedOops
-Duser.timezone=UTC
Alexander Guz
  • 1,334
  • 12
  • 31
  • I have done it for PhpStorm2017.2 and it doesn't effect(I made restart). I added to coppied file to /Users/aprosciak/Library/Preferences/PhpStorm2017.2/phpstorm.vmoptions line -Duser.timezone=UTC. Any idea what could go wrong? – Arkowsky Jan 24 '18 at 08:05
0

After phpstorm.vmoptions file modification with -Duser.timezone=UTC line I've seen correct return only from NOW() function but incorrect from the queries to a table like SELECT timestamp FROM ...

Only adding a variable timezoneAsRegion with false value to Advanced tab of connection without any phpstorm.vmoptions changes helped me to return correct timezone from the table.

Documentation link: https://www.jetbrains.com/help/phpstorm/2016.1/data-sources-and-drivers-dialog.html#advancedTab

vvolkov
  • 1,172
  • 8
  • 10