📄 sample3_31.java
字号:
package chapter03.sample3_31;
import java.util.Date;
public class Sample3_31 {
public static void main(String[] args) {
Date now = new Date();
int year = now.getYear() + 1900;// 提取当前年份
int month = now.getMonth() + 1;// 提取当前月份
int date = now.getDate();// 提取当前天
String day = "";
// 提取当前星期数,并为其转义
switch (now.getDay() + 1) {
case 0:
day = "星期日";
break;
case 1:
day = "星期一";
break;
case 2:
day = "星期二";
break;
case 3:
day = "星期三";
break;
case 4:
day = "星期四";
break;
case 5:
day = "星期五";
break;
case 6:
day = "星期六";
break;
}
int hour = now.getHours();// 提取当前小时
int temp = now.getMinutes();// 提取当前分钟
String min = temp < 10 ? "0" + temp : "" + temp;
temp = now.getSeconds();// 提取当前秒种
String sec = temp < 10 ? "0" + temp : "" + temp;
System.out.println("现在的时刻为:" + year + "年" + month + "月" + date + "日 "
+ day + " " + hour + "点" + min + "分" + sec + "秒");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -