Redhat Linux and its Oracle JRE, IBM JRE time, time zone, and daylight savings

Source: Internet
Author: User
Tags current time time zones local time

For large systems such as clustering and distributed, time and its synchronization are very important issues. The study of Redhat Linux and JRE (including Oracle JRE,IBM JRE) is summarized below.

1, the view of the time

The usual time can be divided into local time and UTC time, and local time is used under Linux for date viewing:

# date

Wed Oct 17:38:06 Brst 2012

This is usually the time zone and the time value that includes the daylight saving period calculations. All systems that use Linux time print out this time.

UTC time refers to the time of standard Greenwich and 0 time zones, and does not contain calculations for daylight savings. UTC time Viewing mode is:

# Date-u

Wed Oct 19:38:12 UTC 2012

Basically: local time =UTC time + time difference

There is also the hardware time, and the time that is stored on the BIOS, viewing mode:

# Hwclock

Wed Oct 05:38:16 PM BRST-0.328544 seconds

To view the time of the JRE, we wrote a tool:

# Cat Testtimezone.java

Import Java.text.SimpleDateFormat;
Import java.util.Date;
Import Java.util.TimeZone;
public class Testtimezone
{
                private static String Default_format = "Yyyy-mm-dd HH:mm:ss. SSS (z) ";
                private static SimpleDateFormat SDF = new SimpleDateFormat (default_format);
                public static void Main (String args[])
                {
                                Date dt = new Date ();
                                System.out.println ("Current Time:\t" + sdf.format (dt));
                                Sdf.settimezone (Timezone.gettimezone ("UTC"));
                                System.out.println ("UTC time:\t" + sdf.format (dt));
                                SYSTEM.OUT.PRINTLN ("ENV variable user.timezone:" + system.getproperty ("User.timezone"));
                }

In order to be compatible with the low version JRE, compile with JDK1.4 and run:

#/usr/java/j2sdk1.4.2/bin/java Testtimezone.java

#java Testtimezone

Current time:2012-10-31 15:57:47.014 (Brst)

UTC Time:2012-10-31 17:57:47.014 (UTC)

ENV variable User.timezone:america/bahia

2,linux time and JRE time relationship

Explain the relevant configuration file first:

/etc/localtime:linux system time zone files, defining the Linux time zone and daylight saving rules

/etc/sysconfig/clock:linux and JRE to use the file, may not have this file, file content such as:

Cat/etc/sysconfig/clock

# The ZONE parameter is only evaluated by System-config-date.

# The timezone of the ' system is ' defined by the contents of/etc/localtime.

Zone= "Asia/shanghai"

Utc=true

Arc=false

Zone refers to the time zone, which works for the JRE, and is overwritten by the definition in/etc/localtime for Linux

UTC is the hardware store is UTC time, if true, the hardware time as UTC time, the Linux system startup will this event plus time zone and daylight savings time difference calculates the local time, if False, then the hardware is the local time, the timezone and daylight saving rules expire.

When the Linux system starts, the hardware time is read first, and then the time is calculated based on the definition in the above configuration file.

But the JRE's time is handled independently, and the JRE gets the hardware time independently of the Linux sample, and then calculates the time of the JRE based on the JRE's time zone and daylight savings rules. The time zone determination rule for the JRE is: first determine whether there are TZ system variables (also for User.timezone, in the Java program can also be specified by the parameter-duser.timezone), if there is the value of the TZ variable, if not take/etc/sysconfig/ The zone value in the clock.

As you know, updates to the time zone and daylight saving rules need to update both the Linux and JRE related configuration and rules. The Linux daylight saving time rule is under/usr/share/zoneinfo/; Oracle JRE Daylight saving time rule in: $JAVA _HOME/LIB/ZI;IBM JRE Daylight saving time rule in $ibm_java_home/lib/core.jar.

This article from the "Small Hebebe Technical Space" blog, please be sure to keep this source http://babyhe.blog.51cto.com/1104064/1045570

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.