📄 dateformatter.java
字号:
package examples.i18n;
import java.text.DateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
/** Class to demonstrate the use of the Calendar
* class and date formatting
*/
public class DateFormatter {
/** main entrypoint - starts the application
* @param args not used
*/
public static void main( String[] args) {
Calendar calDefault = Calendar.getInstance();
Date today = calDefault.getTime();
test( "DEFAULT style",
DateFormat.DEFAULT, today );
test( "FULL style", DateFormat.FULL, today );
test( "LONG style", DateFormat.LONG, today );
test( "MEDIUM style", DateFormat.MEDIUM, today );
test( "SHORT style", DateFormat.SHORT, today );
}
/** Common test routine
* @param label the label for the test
* @param style the DateFormat style to be used
* @param date the date to be formatted
*/
static void test( String label, int style,
Date date ) {
System.out.println( label );
DateFormat df
= DateFormat.getDateInstance( style );
System.out.print( "\tDefault locale: " );
System.out.println( df.format( date ) );
df = DateFormat.getDateInstance( style,
Locale.ITALY );
System.out.print( "\tLocale for Italy: " );
System.out.println( df.format( date ) );
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -