计算机时间的转化

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);
	}
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值