java如何将时间戳转换为时间字符串? 如:1277106667 => 2010-06-21 15:51:07 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 喔,原来是秒数....SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss")String date = sdf.format(new Date(时间戳*1000));System.out.println(date); 不好意思,有两个小修正SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")String date = sdf.format(new Date(时间戳*1000L));System.out.println(date); 你这是将格林时间的毫秒转化成字符串public String convert(long mill){ Date date=new Date(mill); String strs=""; try { SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); strs=sdf.format(date); } catch (Exception e) { e.printStackTrace(); } return strs; } long nowTime=System.currentTimeMillis(); System.out.println(test.convert(nowTime));结果 2010-06-21 04:16:16 long time=1277106667; Date date=new Date(time); SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String str=format.format(date); System.out.println(str);结果是:1970-01-16 02:45:06 为什么不是2010-06-21 15:51:07呢 sorry。原来是秒数,不是毫秒数啊~ SimpleDateFormat 应该import哪个包呢?为什么我编译的时候说找不到符号SimpleDateFormat呢? import java.text.SimpleDateFormat; String str = String.format("%tF %<tT", 1277106667000L);PS:你那个时间戳少了三个“0”。代码在 JDK 1.5 及以上版本有效。 long数字就是距离1970年1月1日0:0:0的描述 大概就是这个意思。 不考虑多线程就用SimpleDateFormat考虑多线程用 FastDateFormat JDBC的数据库操作都是同步操作,有没有异步的方法? 怎么写一个自己的安全管理器,它判断用户的密码是否正确,如果正确就可以读写文件。大侠们帮忙 请教关于JDBC的rs.next()的问题 写入日文xml文档出现了乱码的问题 java中static方法问题 MySQL一个小问题请教大家! 100分!各位看看这个java实现的telnet客户端怎么不对阿!! 请教几个基础问题 整日与电脑为伍,致使头发日渐稀少,请问个位该怎么办? new Oracle 问题 求助!不出窗口!!怎么回事?急等!! 帮忙看下程序为什么不能实现interrupt方法?在线求大神解答
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss")
String date = sdf.format(new Date(时间戳*1000));
System.out.println(date);
String date = sdf.format(new Date(时间戳*1000L));
System.out.println(date);
Date date=new Date(mill);
String strs="";
try {
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
strs=sdf.format(date);
} catch (Exception e) {
e.printStackTrace();
}
return strs;
}
System.out.println(test.convert(nowTime));结果 2010-06-21 04:16:16
long time=1277106667;
Date date=new Date(time);
SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String str=format.format(date);
System.out.println(str);结果是:1970-01-16 02:45:06 为什么不是2010-06-21 15:51:07呢
为什么我编译的时候说找不到符号SimpleDateFormat呢?
考虑多线程用 FastDateFormat