返回方法去掉时间后带的毫秒数

时光紧张,先记一笔,后续优化与完善。

    

截取返回时光对象格式yyyy-MM-dd HH:mm:ss的字符串( 去掉时光后带的毫秒数)

    

Static SimpleDateFormat dateformatAll= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//定义返回的日期格式

    每日一道理
书籍好比一架梯子,它能引领人们登上文化的殿堂;书籍如同一把钥匙,它将帮助我们开启心灵的智慧之窗;书籍犹如一条小船,它会载着我们驶向知识的海洋。

    

//去掉后带.123时光的毫秒数方法
public static String getTimestampStringAbortMillisecond(Timestamp ts){
 if(ts==null){//如果时光为空返回当前时光
  return dateformatAll.format(getCurrentTimestamp());
 }
 return dateformatAll.format(ts);//格式化传过来的时光就能够去掉毫秒数
}
//频仍地应用new Timestamp(new Date().getTime())方法获得当前的timestamp

    

public static Timestamp getCurrentTimestamp(){
 return new Timestamp(new Date().getTime());//获取当前的时光
}

文章结束给大家分享下程序员的一些笑话语录: 《诺基亚投资手机浏览器UCWEB,资金不详或控股》杯具了,好不容易养大的闺女嫁外国。(心疼是你养的吗?中国创业型公司创业初期哪个从国有银行贷到过钱?)

原文地址:https://www.cnblogs.com/xinyuyuanm/p/3078502.html