方法1:

```
{field:'dispatchDate', title:'派單日期', sortable:true, align:'center',
? ? ????????????formatter:function (value, row, index) {
????????????????????return changeDateFormat(value)
????????????????}
},
//轉(zhuǎn)換日期格式(時(shí)間戳轉(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;
? ? }
}
```
方法二:
換個(gè)思路在實(shí)體類的get方法上上添加使用@JsonFormat(pattern ="yyyy-MM-dd HH-mm-ss")
```
@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss")
privateDate updateTime;
```
上面直接這么使用,在我們中國(guó)來(lái)講和我們的北京時(shí)間,會(huì)相差8個(gè)小時(shí),因?yàn)槲覀兪?a target="_blank">東八區(qū)(北京時(shí)間)。
所以我們?cè)诟袷交臅r(shí)候要指定時(shí)區(qū)(timezone),代碼如下:
/**更新時(shí)間? 用戶可以點(diǎn)擊更新,保存最新更新的時(shí)間。**/
```
@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;
? ? }
```