Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to specify time zone for DB data source in PHPStorm?

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?

like image 842
Alexander Guz Avatar asked Mar 05 '15 08:03

Alexander Guz


2 Answers

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()

like image 69
vandersondf Avatar answered Sep 23 '22 20:09

vandersondf


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
like image 37
Alexander Guz Avatar answered Sep 21 '22 20:09

Alexander Guz