Android in the SimpleDateFormat detailed

Source: Internet
Author: User
Tags string format

SimpleDateFormat is a simple format that requires passing in the specified parameters, including parameter names and formats, to match the string to parse;

Android api:http://developer.android.com/reference/java/text/simpledateformat.html

How to use:

SimpleDateFormat SDF = new SimpleDateFormat ("Yyyy-mm-dd ' T" hh:mm:ss. SSS ' Z ');  
Date qdate = new GregorianCalendar (0,0,0). GetTime ();  
try {  
   qdate = sdf.parse (dt);  
} catch (ParseException e) {  
    log.d (TAG, "Date parsing exception.", E);  
}

DT is the label format for XML, as follows:

<updated>2014-03-24T07:48:34.609Z</updated>

The specified style needs to be matched, otherwise it cannot be resolved;

namely: Yyyy-mm-dd ' T ' hh:mm:ss. SSS ' Z '

You can also use the Convert to string format

Such as:

SimpleDateFormat SDF = new SimpleDateFormat ("hh.mm");  
String datestring = Sdf.format (date);

Author: csdn Blog spike_king

See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/OS/extra/

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.