Java 程式以大寫形式顯示日期和時間資訊
首先,建立一個格式化程式和一個日曆物件。
Formatter f = new Formatter(); Calendar c = Calendar.getInstance();
要顯示完整日期和時間資訊,請使用“c”轉換字元。但是,要大寫顯示,請使用“Tc”。
f = new Formatter();
System.out.println(f.format("
Date and Time (uppercase): %Tc
", cal));以下是一個示例 −
示例
import java.util.Calendar;
import java.util.Formatter;
public class Demo {
public static void main(String args[]) {
Formatter f = new Formatter();
Calendar cal = Calendar.getInstance();
System.out.println("Current date and time: "+cal.getTime());
f = new Formatter();
System.out.println(f.format("
Date and Time (uppercase): %Tc
", cal));
}
}輸出
Current date and time: Mon Nov 26 07:44:39 UTC 2018 Date and Time (lowercase): MON NOV 26 07:44:39 UTC 2018
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP