main.java
来自「java的经典例子」· Java 代码 · 共 36 行
JAVA
36 行
import java.text.DateFormatSymbols;import java.text.SimpleDateFormat;import java.util.*;class Main { public static void main(String[] args) { // Create a date formatter. SimpleDateFormat dateformat = new SimpleDateFormat (); // Create an instance of DateFormatSymbols. DateFormatSymbols dfs = new DateFormatSymbols(); // Modify the short month string to be all uppercase. dfs.setShortMonths(new String[] {"JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC"}); // Apply pattern. dateformat.applyPattern("dd-MMM-yyyy - H:mm:ss zzzz"); // Apply the symbols to this date format. dateformat.setDateFormatSymbols(dfs); // Format the current time. String dateString = dateformat.format(new Date()); System.out.println(dateString + "\n"); // "27-NOV-1997 - 5:44:47 GMT+01:00" // Get and print out the first short month string. String month = dateformat.getDateFormatSymbols().getShortMonths()[0]; System.out.println(month); // "JAN" }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?