Default time zone problem in java programming

In the process of java programming, the processing of date and time is generally used. Since time is involved, there must be a time zone problem. In general, we use the time zone of the operating system, so no need to specify the time zone, java will automatically use the system time zone as the default time zone. The application code does not involve the issue of specifying the time zone.

However, the java program running in the aws public cloud ec2 instance needs to pay special attention to the default time zone, because the ec2 itself is a virtual machine, and the ami image, which is the operating system image, needs to be specified when starting the instance. If the time zone is not configured, it is likely to be the utc time zone or another time zone, so the default time zone used by your java program may not be the time zone you expect. This way your date related programs will have problems. Maybe when you are developing locally, your local environment is the local time zone, but in the production environment, the time zone is not necessarily. Therefore, when developing aws cloud applications, special attention should be paid to specifying the default time zone in your java program, or specifying it through java entry parameters.

There is another situation, if your program needs to be deployed to docker to run, there is also this problem.
Generally, the default time zone is specified at the beginning of the main method, TimeZone.setDefault(TimeZone.getTimeZone("GMT"))

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326564496&siteId=291194637