时间戳转换


1  通过java,如下:

```java
   public static String timeStamp2Date(String time) {
    Long timeLong = Long.parseLong(time);
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//要转换的时间格式
    Date date;
    try {
        date = sdf.parse(sdf.format(timeLong));
        return sdf.format(date);
    } catch (ParseException e) {
        e.printStackTrace();
        return null;
    }
}   


2 js中转换,利用bootstraptable 加载,写一个方法返回




 columns: [
		     {   title: "开盘时间",
		        field: "openTime",
		        formatter: function (value, row, index) {
		            return changeDateFormat(value)
		        }



function changeDateFormat(cellval) {
         var dateVal = cellval + "";
         if (cellval != null) {
             var date = new Date(parseInt(dateVal.replace("/Date(", "").replace(")/", ""), 10));
             var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
             var currentDate = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
             
             var hours = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
             var minutes = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
             var seconds = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
             
             return date.getFullYear() + "-" + month + "-" + currentDate + " " + hours + ":" + minutes + ":" + seconds;
         }
     }
原文地址:https://www.cnblogs.com/gloria-liu/p/9392097.html