public class time
{
/**
* @param args
*/
public static void main(String[] args)
{
long milliseconds;
long millisecond;
long second;
long minute;
long hour;
long day;
int leap,year,countmonth=0;
String[] month={"January","February","March","April","May","July","June","August","September","October","November","December"};
//month的英文
milliseconds=System.currentTimeMillis();//得到计算机时间
millisecond=milliseconds%1000;//
second=milliseconds/1000;//化秒
minute=second/60;//化分
hour=minute/60;//化时
day=hour/24;//化天
// System.out.println("Milliseconds is:"+milliseconds);
// System.out.println("Millisecond is:"+millisecond);
// System.out.println("second is:"+second%60);
// System.out.println("minute is:"+minute%60);
// System.out.println("hour is:"+hour%24);
leap=2;//闰年计时器
year=1970;//年份计时器
while(day>=365)
{
if(leap==4)//闰年时多减
{
day-=366;
leap=1;
year++;
}
else
{
day-=365;
leap++;
year++;
}
}
countmonth=1;//月份计时器
while(day>29)
{
switch(countmonth)
{
case 1:day-=31;break;
case 2:
if(leap==4)
day-=29;
else
day-=28;
break;
case 3:day-=31;break;
case 4:day-=30;break;
case 5:day-=31;break;
case 6:day-=30;break;
case 7:day-=31;break;
case 8:day-=31;break;
case 9:day-=30;break;
case 10:day-=31;break;
case 11:day-=30;break;
case 12:day-=31;break;
}
countmonth++;
}
/*System.out.println("year is:"+year);
System.out.println("day is:"+(day+1));
System.out.println("month is:"+month[countmonth-1]);*/
System.out.println("Current date and time is "+month[countmonth-1]+" "+(day+1)+", "+year+" "+(hour%24+8)+":"+minute%60+":"+second%60);
}
}
计算机时间的转化
最新推荐文章于 2021-07-28 18:41:43 发布