日期:2014-05-18  浏览次数:20757 次

怎么把时间戳转化成时间的正规格式显示出来啊???
怎么把时间戳转化成时间的正规格式显示出来啊???
我得出的时间戳是:1172910248593
在long   DateTemp1=new   Date().getTime();
这个变量上`   怎么转化成yy.mm.hh的形式啊???

------解决方案--------------------
SimpleDateFormate类,创建一个它的对像formate=new SimpleDateFormate( "yyyy-MM-dd hh:mm:ss ") ;然后用formate.formate()...方法.
------解决方案--------------------
Format(Time, "HH:mm:ss ")
------解决方案--------------------
public static final DateFormat getDateTimeInstance(int dateStyle, int timeStyle, Locale aLocale)
获得日期/时间 formatter,该 formatter 具有给定语言环境的给定格式化风格。
参数:
dateStyle - 给定的日期格式化风格。
timeStyle - 给定的时间格式化风格。
aLocale - 给定的语言环境。
返回:日期/时间 formatter。

--------------------------------------------
时间显示方式不同:
(DateFormat.FULL,DateFormat.FULL,Locale.CHINA); 2006年10月8日 星期日 上午05时20分08秒 CST
(DateFormat.FULL,DateFormat.LONG ,Locale.CHINA); 2006年10月8日 星期日 上午05时20分08秒
(DateFormat.FULL,DateFormat.SHORT,Locale.CHINA); 2006年10月8日 星期日 上午5:20
(DateFormat.FULL,DateFormat.DEFAULT,Locale.CHINA); 2006年10月8日 星期日 5:20:08

--------------------------------------------
日期显示方式不同:
(DateFormat.ERA_FIELD,DateFormat.FULL,Locale.CHINA); 2006年10月8日 星期日 上午05时20分08秒 CST
(DateFormat.FULL,DateFormat.FULL,Locale.CHINA); 2006年10月8日 星期日 上午05时20分08秒 CST
(DateFormat.YEAR_FIELD ,DateFormat.FULL,Locale.CHINA); 2006年10月8日 上午05时20分08秒 CST
(DateFormat.LONG ,DateFormat.FULL,Locale.CHINA); 2006年10月8日 上午05时20分08秒 CST
(DateFormat.MEDIUM,DateFormat.FULL,Locale.CHINA); 2006-10-8 上午05时20分08秒 CST
(DateFormat.MONTH_FIELD,DateFormat.FULL,Locale.CHINA); 2006-10-8 上午05时20分08秒 CST
(DateFormat.DEFAULT,DateFormat.FULL,Locale.CHINA); 2006-10-8 上午05时20分08秒 CST
(DateFormat.DATE_FIELD,DateFormat.FULL,Locale.CHINA); 06-10-8 上午05时20分08秒 CST
(DateFormat.SHORT,DateFormat.FULL,Locale.CHINA); 06-10-8 上午05时20分08秒 CST

--------------------------------------------
Date now = new Date(); DateFormat df = DateFormat.getDateTimeInstance(DateFormat.FULL,DateFormat.LONG ,Locale.CHINA);
String s=df.format(now);
DateFormat.getDateTimeInstance(DateFormat.FULL,DateFormat.LONG ,Locale.CHINA);
效果:2006年10月8日 星期日 上午05时20分08秒

------解决方案--------------------
public String getFormatDateString(Date d,String formatStr){
String formatStrEnd= " ";
SimpleDateFormat bartDateFormat = new SimpleDateFormat(formatStr);
formatStrEnd=bartDateFormat.format(d);
return formatStrEnd;
}

d=ResultSet.getData()的结果.
formatstr= "yyyy-MM-dd "(例如)的格式就是2007-02-03