bootstrap table中時間戳轉(zhuǎn)為datetime格式

方法1:


```

{field:'dispatchDate', title:'派單日期', sortable:true, align:'center',

? ? ????????????formatter:function (value, row, index) {

????????????????????return changeDateFormat(value)

????????????????}

},

//轉(zhuǎn)換日期格式(時間戳轉(zhuǎn)換為datetime格式)

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;

? ? }

}

```


方法二:

換個思路在實體類的get方法上上添加使用@JsonFormat(pattern ="yyyy-MM-dd HH-mm-ss")

```

@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss")

privateDate updateTime;

```

上面直接這么使用,在我們中國來講和我們的北京時間,會相差8個小時,因為我們是東八區(qū)(北京時間)。

所以我們在格式化的時候要指定時區(qū)(timezone),代碼如下:



/**更新時間? 用戶可以點擊更新,保存最新更新的時間。**/

```

@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone="GMT+8")

privateDate updateTime;

```

方法三:直接轉(zhuǎn)字符串

```

private String registerDateFormat(Date data) {

? ? ? ? if (data != null) {

? ? ? ? ? ? SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

? ? ? ? ? ? return df.format(data);

? ? ? ? }

? ? ? ? return null;

? ? }

```

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

友情鏈接更多精彩內(nèi)容