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