Search code examples
databasetimezonephpstorm

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?


Solution

  • 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