Brief introduction: Conversion of string and time format

Source: Internet
Author: User
Tags parse string

Conversion of string to time format

-----commonly used methods: 1, stitching the format of the string "Some common methods of string type";

2. SimpleDateFormat format

3. Date format

1, the use of SimpleDateFormat:

1.1 Common methods:

Format (date), formats the given date as a date/time string, and adds the result to the given StringBuffer

Parse (string), parse string literal, generate date type

2. Usage of date:

3. Use of string:

3, output the current time:

Date d = new Date (); Or:

System.out.println (d); System.out.println (New Date ());

4, String type format:

Cahr--charat (index); Returns the char value of the specified index.

String--concat (string); connects the specified string to the end of this string.

Int--indexof (char); Returns the index of the specified string at the first occurrence of this character.

String--indexof (String) returns the index where the specified substring first appears in this string.

Int--length (); Returns the length of this string.

IsEmpty (); Returns true if and only if length () is 0 o'clock.

String[]--split (String), which splits the string according to the given character, string match.

String--tostring (). Returns the object itself (it is already a string).

String--trim (). Returns a copy of the string, ignoring leading and trailing blanks.

5. Enter a time format of "string" to convert it to a date-type time format:

Practice One:

Splits the format of a string to output a string in a specified format
String a = "1990-2-1";
String[] B = a.split ("-");
String da=b[0]+ "Year" +b[1]+ "month" +b[2]+ "Day";
System.out.println (DA);

The--------------output is: February 1, 1990

Exercise two:

  

Brief introduction: Conversion of string and time format

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.