编写一个函数 打印昨天的当前时刻
展开全部
import java.util.Date;
public class yestoday {
public static void main(String[] args){
Date date=new Date();
int year=date.getYear();
int month=date.getMonth();
int zuo;
int hour=date.getHours();
int minute=date.getMinutes();
int second=date.getSeconds();
if(date.getDay()==1){
if(month==1||month==2||month==4||month==6||month==8||month==9||month==11){
zuo=31;
}
else if(month==5||month==7||month==9||month==11){
zuo=30;
}
else if(year/4==0&&year/100!=0||year/400==0){
zuo=28;
}
else{
zuo=29;
}
}
else{
zuo=date.getDay()-1;
}
System.out.print("昨天的当前时刻为"+year+"年"+month+"月"+zuo+"日"+hour+"时"+minute+"分"+second+"秒");
}
}
public class yestoday {
public static void main(String[] args){
Date date=new Date();
int year=date.getYear();
int month=date.getMonth();
int zuo;
int hour=date.getHours();
int minute=date.getMinutes();
int second=date.getSeconds();
if(date.getDay()==1){
if(month==1||month==2||month==4||month==6||month==8||month==9||month==11){
zuo=31;
}
else if(month==5||month==7||month==9||month==11){
zuo=30;
}
else if(year/4==0&&year/100!=0||year/400==0){
zuo=28;
}
else{
zuo=29;
}
}
else{
zuo=date.getDay()-1;
}
System.out.print("昨天的当前时刻为"+year+"年"+month+"月"+zuo+"日"+hour+"时"+minute+"分"+second+"秒");
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询