日期:2014-05-19 浏览次数:20723 次
public int IntegertimeTag(Date date){ int time=0; Calendar c = Calendar.getInstance(); SimpleDateFormat simpledate = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss "); String Send_date = simpledate.format(date); try { time = (int) simpledate.parse(Send_date).getTime(); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } return time; } public Date DatetimeTag(int date){ String time=null; SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); Long now=new Long((long)date); //int 转 long Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(now); time= formatter.format(calendar.getTime()); Date date11=null; try { date11 = formatter.parse(time); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } return date11; }
public class Test { public static void main(String[] args){ Date date = null; date = new Date(); System.out.println(getDateString(date)); System.out.println(getDateLong(date)); System.out.println(getDate(getDateLong(date))); try { System.out.println(getDate(getDateString(date))); } catch (ParseException e) { e.printStackTrace(); } } public static String getDateString(Date date){ return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date); } public static Date getDate(String dateStr) throws ParseException{ return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(dateStr); } public static Long getDateLong(Date date){ return date.getTime(); } public static Date getDate(Long time){ Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(time); return calendar.getTime(); } }
------解决方案--------------------
public static Date getDate(Long time){
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(time);
return calendar.getTime();
}
可以这样写啊
public static Date getDate(Long time){
return new Date(time);
}
------解决方案--------------------