Green Time: Thu may 2017 00:00:00 gmt+0800 (China Standard Time) format conversion

Source: Internet
Author: User
Tags locale

Similar to the Thu May 2017 00:00:00 gmt+0800 (China Standard Time) format, the time is converted to 2017/05/18 or seconds, as follows:


/**
 *@paramDatdstring Thu May 2017 00:00:00 gmt+0800 (China Standard Time) *@returnmonth and year day; */public static string Parsetime (String datdstring) {datdstring = Datdstring.replace ("GMT", ""). ReplaceAll ("\ (. *\\)
    ", ""); Converts a string to a date type, formatted 2016-10-12 simpledateformat format = new SimpleDateFormat ("EEE MMM dd yyyy HH:mm:ss z", Locale.engli
    SH);
    Date Datetrans = null;
        try {Datetrans = Format.parse (datdstring);
    return new SimpleDateFormat ("Yyyy-mm-dd"). Format (Datetrans). Replace ("-", "/");
    catch (ParseException e) {e.printstacktrace ();

return datdstring; }

/**
 *@paramDatdstring "Tue June 12:10:11 gmt+08:00 2016"; *@returnTime sec/public static string Parsehour (String datdstring) {datdstring = Datdstring.replace ("GMT", ""). ReplaceAll ("\
    (.*\\)", "");
    SimpleDateFormat format = new SimpleDateFormat ("EEE MMM dd yyyy HH:mm:ss z", locale.english);
    Date Datetrans = null;
        try {Datetrans = Format.parse (datdstring);
    return new SimpleDateFormat ("HH:mm:ss"). Format (Datetrans);
    catch (ParseException e) {e.printstacktrace ();
return datdstring; }


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.