//时分秒格式//不知为何,出来的时间有点差别 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_
时间: 2024-09-30 06:39:33