public class date{
public static void main(String[] args) {
Calendar d = Calendar.getInstance();
int hour = d.get(Calendar.HOUR_OF_DAY);
if (hour >= 6 && hour < 8) {
System.out.print("早上好,小甜心");
} else if (hour >= 8 && hour < 12) {
System.out.print("上午好,小甜心");
} else if (hour >=12 && hour < 14) {
System.out.print("中午好,小甜心");
}else if (hour >=14 && hour < 18) {
System.out.print("中午好,小甜心");
}else if (hour >=18 && hour < 22) {
System.out.print("中午好,小甜心");
}else if (hour >=22) {
System.out.print("深夜了,小甜心");
}
}
}
现在时间是:x年x月x日 周x x时x时x分x秒
import java.text.SimpleDateFormat;
import java.util.Date;
public class date
{
public static void main(String[] args)
{
Date now=new Date(); //创建一个Date对象,获取当前时间
//指定格式化格式
SimpleDateFormat f=new SimpleDateFormat("现在时间是 "+"yyyy 年 MM 月 dd 日 E HH 点 mm 分 ss 秒");
System.out.println(f.format(now)); //将当前时间袼式化为指定的格式
}
}
编写程序输入今日是星期几
public class date {
public static void main(String[] args) {
System.out.printf(" %1$tA",System.currentTimeMillis());
}
}