CloudFoundry Timezone

2019-03-05 23:14发布

I have developed an application which is very (JodaTime) DateTime centric (calendar and so on). Locally at my computer all works fine. I have deployed my app at cloudfoundry and there no dates are visible in the calendar. I guess that this has something to do with the timezone of cloudfoundry. I have connected my locally running application to the mongodb database in the coud and everything works find. My question now would be how to change timezone at cloudfoundry to CEST (MEZ)?

Thanks a lot!

2条回答
等我变得足够好
2楼-- · 2019-03-05 23:37

Your Java application is going to run in a Linux container, so you can use any Linux or Java method of setting the timezone.

The easy ones that come to mind...

cf set-env <app-name> TZ 'America/Los_Angeles' cf restage <app-name>

or

cf set-env <app-name> JAVA_OPTS '-Duser.timezone=Europe/Sofia' cf restage <app-name>

The first should be generic to any application that respects the TZ environment variable. The second is specific to Java.

If you don't want to use cf set-env you could alternatively set the environment variables via your manifest.yml file.

查看更多
聊天终结者
3楼-- · 2019-03-05 23:54

To expand on @DanielMikusa. (Great Answer)

SAMPLE MANIFEST:

    applications:
- path: .
  buildpack: nodejs_buildpack
  memory: 128M
  instances: 1
  name: sampleCronJobService
  health-check-type: process
  disk_quota: 1024M
  env:
    TZ: Etc/Greenwich
    CF_STAGING_TIMEOUT: 15
    CF_STARTUP_TIMEOUT: 15
    TIMEOUT: 180
    SuperSecret: passwordToTheWorld

WHY I KNOW IT WORKS:

var date = new Date();
var utc_hour = date.getUTCHours();
var local_hour = date.getHours();
console.log('(Timezone) Local Hour: ' + local_hour + ' UTC Hour: ' + utc_hour);

Prints: (Timezone) Local Hour: 23 UTC Hour: 23

If I set the manifest to have TZ: America/Los_Angeles

It Prints: (Timezone) Local Hour: 16 UTC Hour: 23

查看更多
登录 后发表回答