使用Java中的Formatter显示完整的日期和时间信息
首先,创建一个Formatter和Calendar对象。
Formatter f = new Formatter(); Calendar cal = Calendar.getInstance();
现在显示当前日期和时间。我们在这里以小写和大写形式显示了日期-
f = new Formatter();
System.out.println(f.format("\nDate and Time (lowercase): %tc\n", cal));
f = new Formatter();
System.out.println(f.format("Date and Time (uppercase): %Tc\n", 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("\nDate and Time (lowercase): %tc\n", cal));
f = new Formatter();
System.out.println(f.format("Date and Time (uppercase): %Tc\n", cal));
}
}输出结果
Current date and time: Mon Nov 26 07:24:21 UTC 2018 Date and Time (lowercase): Mon Nov 26 07:24:21 UTC 2018 Date and Time (uppercase): MON NOV 26 07:24:21 UTC 2018
热门推荐
10 诗词送行祝福语大全简短
11 新房开工吉日祝福语简短
12 50多岁生日简短祝福语
13 安徽疫情祝福语简短英语
14 农民朋友发财祝福语简短
15 对生活祝福语简短精辟
16 搬家词简短祝福语朋友
17 女神结婚快乐祝福语简短
18 文学短句祝福语大全简短