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

更新于:2019 年 7 月 30 日

397 次浏览

开启你的 职业生涯

完成课程认证

立即开始
广告
© . All rights reserved.