Java – Can there be a machine without a time zone?

Can there be a machine without a time zone?… here is a solution to the problem.

Can there be a machine without a time zone?

I assume that all systems (Windows, Mac, Linux, Solaris, SunOS, HP-UX, AIX, FreeBSD, NetWare, OS/400, etc.) have time zone values. So I wrote the following program to get the local time zone of the system:

import java.text.DateFormat;
public class LocalTimeZone {
    public static void main(String[] args) {
        String local_time_zone;
        DateFormat df = DateFormat.getTimeInstance(DateFormat.FULL);
        local_time_zone=df.getTimeZone().getID();
        System.out.println("local time zone: " + local_time_zone);
    }
}

Output:
Local time zone: Asia/Kolkata

The time zone

value is set in my machine, so the output shows my local time zone.

Is it possible to have a machine that does not have a time zone set?

Solution

This is indeed possible and is common on embedded Linux systems. For example, when the entire operating system must run from 64MB of flash memory, vendors may choose not to include the time zone when compiling the Linux stack for their devices.

Even without the setting, I think Java will return a default value (probably UTC) because it runs at a higher level.

As far as I know, there’s always a time zone set on Windows. (I’m not sure about WindowsCE).

Related Problems and Solutions