2

To run my web app, I need to set my timezone to UTC on my MacBook. I can do this temporarily by opening a Konsole and entering

sudo ln -sf /usr/share/zoneinfo/UTC /etc/localtime

However, my timezone returns to normal when I restart my machine!

Any advice?

Edit : The response to this question by 'Celada' implies that I can just make my Server UTC. I am using Apache Tomcat 7. Adding to Celada's response, how can I make it UTC?

Update - 3rd April : Following Celada's response, I have tried adding SetEnv TZ UTC at the top of startup.sh. This didn't seem to make a difference. After some research, I tried adding export JAVA_OPTS="-Duser.timezone=UTC" to startup.sh, but this too had no effect. Am I adding the correct command to the correct file?

3 Answers 3

1

I assume that if you would use the control panel to change the timezone, your change wouldn't be squashed on every reboot.

If you are concerned that the timezone is reverting every time you restart, then it sounds like you want to make the change permanent, not temporary, so in that case why don't you just use the control panel?

If this change is just for your web app, then why don't you change the timezone just for the web server instead of globally on the machine? This should be as simple as adding

SetEnv TZ UTC

to the end of /etc/apache2/httpd.conf.

If that doesn't work, it might be because the TZ variable would need to be set before Apache starts instead of being set by Apache. In that case, the following is more complicated, but is sure to work:

  1. Edit /System/Library/LaunchDaemons/org.apache.httpd.plist

    Add the lines

    <key>EnvironmentVariables</key>
    <dict>
            <key>TZ</key>
            <string>UTC</string>
    </dict>
    

    just before the line that reads </dict> near the bottom

  2. Reload that config

    launchctl unload /System/Library/LaunchDaemons/org.apache.httpd.plist
    launchctl load /System/Library/LaunchDaemons/org.apache.httpd.plist
    

All of this needs to be done as root.

10
  • Hi Celada, thanks for your response. What do you mean by 'Control Panel'? Bare in mind I am on a Mac, not Windows. I have found a Timezone option in 'Date & Time' of System Preferences, but saw no option for UTC.
    – Andy A
    Mar 30, 2012 at 13:55
  • Not "Control Panel"? The technical term for the individual items in there used to be 'CDev', but I think that term might be obsolete. So, what I mean is whatever they call it these days. Sorry, I am not in front of my MacBook now (it's at home) so I can't check. Anyway, I'm surprised that there isn't a UTC or UTC-equivalent timezone you can set from there. If you can't find one, then try the Apache SetEnv solution instead?
    – Celada
    Mar 30, 2012 at 14:28
  • Ill try the Apache idea. I'm currently looking for the file I need to add this to. ... (if you can guide me, please do)
    – Andy A
    Mar 30, 2012 at 14:41
  • Mmm, ye, I'm inexperienced with this. What file do I add the line to? Is it one of the files in the conf folder in my apache-tomcat-7.0.26 folder? (Thats a complete guess)
    – Andy A
    Mar 30, 2012 at 14:52
  • I updated the question with more information about how to set an environment variable to Apache. HOWEVER, I see from your latest comment that you might not be using the Apple-supplied default Apache but rather tomcat. If so, you will need to edit the conf file (for the SetEnv version) or launch script (for the launchctl version) corresponding to that webserver. I am not sure which files those would be for you because I don't know where/how your tomcat installation is done. But I hope you can locate the analogous files.
    – Celada
    Mar 30, 2012 at 15:01
0

If the symbolic link works, you can recreate that symbolic link at startup. See Creating launchd jobs

0

Bingo. I have managed to set my tomcat timezone to UTC. In bin/catalina.sh I added CATALINA_OPTS=-Duser.timezone=UTC

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .