Java Date time zone settings (GMT and CST)

The difference between CST and GMT time

Origin of the problem:

​ When learning java.util.Date&java.sql.Date, I found the output result: Sun Nov 22 13 45CSTIn 2020, I checked the information and researched.

Main:

​About time formats: GMT, UTC, CST, ISO. The following mainly summarizes CST and GMT.

Time format:
  • GMT: (GreenwichMeanTime, GMT), the standard time of Greenwich location

    Greenwich is the location of the original Greenwich Observatory in the southern suburbs of London, England. It is also the starting point of geographical longitude in the world. Major events in the world are recorded in Greenwich local time.

    ​ Based on Greenwich Mean Time, people can easily calculate the relative local time.

    (London, UK is the 0 time zone, and Beijing, China is the East Eighth District. In other words, GMT is 0:00 on the 1st, and the corresponding Beijing time is 8:00 am on the 1st)

  • CST: But represents four different time zones at the same time.

    • Central Standard Time (USA) UT-6:00
    • Central Standard Time (Australia) UT+9:30
    • China Standard Time UT+8:00
    • Cuba Standard Time UT-4:00
  • UTC

    Coordinated Universal Time, also known as Universal Unified Time, Universal Standard Time, and International Coordinated Time. Since the English (CUT) and French (TUC) abbreviations are different, as a compromise, the abbreviation is UTC.

    Coordinated Universal Time is based onatomic timeBased on the length of seconds, try to be as close as possible touniversal timeA time measurement system.

  • ISO: A method of expressing time

Notice:

​ GMT is the former Universal Time, and UTC is the current Universal Time.

GMT and UTC time can be considered the same, but UTC is more accurate.

In the example, Date’s CST&GMT (conversion)

package Five_day;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;

public class Demoone {
    public static void main(String[] args) {
        
        //Get the current time
        Date now = new Date();
        System.out.println("Date default CST format is: ");
        System.out.println(now);

        System.out.println("-----------------------------");

        //Convert CST time to GMT
        DateFormat gmtDateFormat = new SimpleDateFormat("EEE,d-MMM-yyyy HH:mm:ss z ", Locale.ENGLISH);
        gmtDateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
        String dateStr = gmtDateFormat.format(now);
        System.out.println("Convert to GMT:");
        System.out.println(dateStr);

    }
}

/*
    Output result:
            The default CST format of Date is:
            Sun Nov 22 13:27:45 CST 2020
            -----------------------------
            Converted to GMT format is:
            Sun,22-Nov-2020 05:27:45 GMT
*/

Related Posts

ES ElasticSearch Connection reset by peer problem solving

Mockito detailed tutorial

Install docker on Mac (easy installation solution)

DataSourceTransactionManager Summary

[Wuji Low Code] Low code platform development diary, low code platform sql programming

[Exception]The field file exceeds its maximum permitted size of 1,048,576 bytes.

Android studio button click page jump

Java project: Design and implementation of online Heihei network disk system (java+Springboot+ssm+mysql+maven)

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

*