When outputting date information, it is often necessary to output date formats in different formats, and this example describes the date formatting methods in the string string class, which use different ways to output the date format parameter values of the string class, which can be combined to implement a date string in a special format.
Ideas are as follows: For example, to output the English abbreviation of the month, the format () method of the String class, the first parameter specifies that the locale is locale.us, the default is a number, the second parameter is%TB for the month abbreviation, and the third parameter is the date () class object.
The code is as follows:
Copy Code code as follows:
Import Java.util.Date;
Import Java.util.Locale;
public class Example1 {
public static void Main (string[] args) {
Date today = new Date ();
The formatted string is the English abbreviation for the month
String a = String.Format (locale.us, "%TB", today);
System.out.println ("formatted string is the English abbreviation for the Month:" + a);
The formatted string is written in English all for the month
String B = String.Format (locale.us, "%TB", today);
System.out.println ("formatted string is the English abbreviation for the month:" + b);
The formatted string is a week (e.g., Monday)
String C = String.Format ("%ta", today);
SYSTEM.OUT.PRINTLN ("Month formatted string is week:" + C);
The formatted string is a week (e.g., Monday)
String d = String.Format ("%ta", today);
System.out.println ("Formatted string is week:" + D);
The formatted string is a 4-bit year value
String e = String.Format ("%ty", today);
SYSTEM.OUT.PRINTLN ("The formatted string is a 4-bit year value:" + E);
The formatted string is a 2-bit year value
String f = String.Format ("%ty", today);
SYSTEM.OUT.PRINTLN ("The formatted string is a 2-bit year value:" + f);
The formatted string is a 2-bit month value
String g = String.Format ("%tm", today);
System.out.println ("formatted string is a 2-bit month value:" + g);
The formatted string is a 2-bit date value
String h = String.Format ("%td", today);
System.out.println ("formatted string is a 2-bit date value:" + h);
The formatted string is a 1-bit date value
String i = String.Format ("%te", today);
System.out.println ("formatted string is a 1-bit date value:" + i);
}
}
Effect as shown: