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

方法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;

? ? }

```

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

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