GMT time format conversion (Mon Feb 08:00:00 gmt+08:00 2012)

Source: Internet
Author: User
Tags dateformat locale

Ordinary time conversion problem I here is no longer wordy, I think everyone should be that kind of low-level conversion problem, now I would like to summarize how to convert GMT time format, this format conversion method is not a lot of online, so it is necessary to summarize, but also for the needs of friends a little help.

First, let's look at the time format for GMT:

Mon Feb 08:00:00 gmt+08:00 2012 There may be other formats like Sun Sep 08:00:00 gmt+08:00 just in order to change it.

So how do we convert this format to the normal date format, with the following method:

The first method of implementation:

Import java.text.ParseException;
Import Java.text.SimpleDateFormat;
Import java.util.Date;
Import Java.util.Locale;

/**
 *
 * @author yaohucaizi
 *
/public class DateFormat {public

    static void Main (string[] args) Throws ParseException {
        String s = "Mon Feb 08:00:00 gmt+08:00";      String s = "Sun Sep 08:00:00 gmt+08:00";
        SimpleDateFormat SF = new SimpleDateFormat ("EEE MMM dd hh:mm:ss z yyyy", locale.english);      SimpleDateFormat SF = new SimpleDateFormat ("EEE MMM dd yyyy hh:mm:ss z", locale.english);
        Date date = Sf.parse (s);
        SimpleDateFormat SDF = new SimpleDateFormat ("Yyyy-mm-dd HH:mm:ss");
        String result = Sdf.format (date);
        SYSTEM.OUT.PRINTLN (result);
    }
}

The second method:

First convert the GMT date into a long number of milliseconds and then further convert to see the code:

Import java.text.ParseException;
Import Java.text.SimpleDateFormat;
Import Java.util.Date;

Import Java.util.Locale; /** * * @author Yaohucaizi */public class DateFormat {public static final String SOURCE = "Wed Feb 13 08:00:00 +

    0800 2012 "; public static void Main (string[] args) throws ParseException {SimpleDateFormat SDF = new SimpleDateFormat ("EEE MM
        M DD HH:mm:ss Z yyyy ", New Locale (" 中文版 "," China ");
        Date mydate = Sdf.parse (SOURCE);
        System.out.println (mydate);
        Sdf.applypattern ("EEE MMM dd HH:mm:ss Z yyyy");
        System.out.println (Sdf.format (mydate));
        SimpleDateFormat sdf2 = new SimpleDateFormat ("Yyyy-mm-dd HH:mm:ss", New Locale ("Chinese", "China");
        System.out.println (Sdf2.format (mydate));
        Sdf2.applypattern ("yyyy mm month DD day hh" mm min ss seconds ");
        System.out.println (Sdf2.format (mydate));
        Long miliseconds = Mydate.gettime (); System.out.println ("The number of milliseconds this Date object has elapsed since January 1, 1970 00:00:00 GMT is:" +Miliseconds + "milliseconds"); }
}

The output is:

        Mon Feb 08:00:00 gmt+08:00
        mon 08:00:00 +0800
        2012-02-13 08:00:00
        February 13, 2012 08:00 00 seconds 
   the number of milliseconds this Date object has elapsed since January 1, 1970 00:00:00 GMT: 1329091200000 milliseconds

GMT (Greenwich Mean time) is Greenwich Normal:
Because the Earth's orbit is not circular, its operating speed changes with the distance between the Earth and the sun, so the sun is not uniform. The length of the solar day is also affected by the inclination of the earth's axis of rotation relative to the orbital surface. To correct the inhomogeneity above, astronomers calculate the effect of the Earth's non-circular trajectory and polar axis tilt on the sun. When the sun is flat, it refers to the revised view of the sun. When the sun is flat on the Greenwich meridian, it is called Universal Time (UTC), also known as Greenwich Mean (GMT).


If you want to collect reproduced friends, please respect the author's intellectual property, thank you.


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.