首页 > 其他 > 详细

long型转日期型

时间:2015-09-12 12:09:28      阅读:214      评论:0      收藏:0      [点我收藏+]
//时分秒格式
//不知为何,出来的时间有点差别

public class Test {
public static void main(String[] args) throws Exception {
long time = 25978000;
System.out.println(getTime(time));
}
public static String getTime(long time) {
String str = "" ;
time = time / 1000;
int s = (int) (time % 60);
int m = (int) (time / 60 % 60);
int h = (int) (time / 3600);
str = h + "小时" + m + "分" + s +"秒";
return str ;
}
}

//年月日时分秒
long timeTemp = System.currentTimeMillis(); //25978000;
long time = timeTemp; 
long mSec = time % 1000; 
time /= 1000; 
long year = time/(365*24*3600);
time = time%(365*24*3600);
long month = time/(30*24*3600); 
time = time % (30*24*3600);
long day = time/(24*3600);
time = time % (24*3600); 
long hour = time/3600;
time = time % 3600; 
long min = time/60;
time = time % 60; 
long sec = time;
System.out.println(timeTemp+"毫秒是:"+year+"年"+month+"月"+day+"天"+hour+"小时"+min+"分钟"+sec+"秒零"+mSec+"毫秒");

//此方法与系统时间相一致
long dd = 2597800000000;
Date d = new Date(dd);
SimpleDateFormat f = new SimpleDateFormat("YYYY:MM:DD:HH:mm:ss");
System.out.println(f.format(d));


//
先把long型转换为日历日期型
long aa = 25978000;
Date date = new Date();
date.setTime(aa * 1000);
Calendar cal=Calendar.getInstance();
cal.setTime(date);

再通过日期类获取时分秒,并组合成你要的字符串
cal.HOUR、cal.MINUTE、cal.SECOND。


http://zhidao.baidu.com/link?url=V3fOH9IjlKlVvSmpyedFgrzJCJlUEE7y2GHYeRsKZxEUbN4Bt_-Fx-Ipq6UX6C1fH0xfVud4fgUmN0unhhkZa_

long型转日期型

原文:http://www.cnblogs.com/LuoXiaoTing604404828/p/4802695.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!