转:http://yxwang0615.iteye.com/blog/1310603
格林尼治时间是从1970年1月1日,00:00:00 GMT到最后修改时间的返回值。
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm", Locale.ENGLISH);
- String datetime = sdf.format(Long.parseLong("1323842302")*1000);
- System.out.println(datetime);
如果需要24小时制的时间 把hh换为HH即可
转载一个工具类:可以将最近时间显示为几秒、分钟、小时:
- import java.text.SimpleDateFormat;
- import java.util.Date;
- import java.util.Locale;
- public class TimeUtil {
- private String getTimeStr(Date date) {
- Date today = new Date();
- long interval = today.getTime() - date.getTime();
- today.setHours(23);
- today.setMinutes(59);
- today.setSeconds(59);
- boolean isSameDay = (interval / 86400000) == 0 ? true : false;
- if (isSameDay) {
- if (interval < 60 * 1000) {
- return (interval / 1000) + "秒前";
- } else if (interval < 60 * 60 * 1000) {
- return (interval / (60 * 1000)) + "分前";
- } else {
- return (interval / (60 * 60 * 1000)) + "小时前";
- }
- } else {
- SimpleDateFormat dateFormat;
- dateFormat = new SimpleDateFormat("MM-dd hh:mm", Locale.ENGLISH);
- return dateFormat.format(date);
- }
- }
- public String getTimeStr(long date) {
- return getTimeStr(new Date(date * 1000));
- }
- }
- 2011-12-14