一、题目需求
获取当前时间戳,实现分时问候
二、代码展示
/*
* Copyright (c) 2020, 2023, webrx.cn All rights reserved.
*
*/
package com.it;
import javax.xml.crypto.Data;
import java.util.Date;
/**
* <p>Project: chat - Ex02</p>
* <p>Powered by webrx On 2023-07-06 19:41:27</p>
* <p>描述:<p>
*
* @author 简单遗忘 [814736551@qq.com]
* @version 1.0
* @since 17
*/
public class Ex02 {
public static void main(String[] args) {
//实现分时问候
Date d=new Date();
int x=d.getHours();
if(x>=6&&x<8){
System.out.println("早上好");
} else if (x>8&&x<12) {
System.out.println("上午好");
} else if (x>=12&&x<14) {
System.out.println("中午好");
} else if (x>=14&&x<18) {
System.out.println("晚上好");
} else if (x>=18&&x<22) {
System.out.println("晚上好");
}
}
}
三、运行截图