問題:國際標(biāo)準(zhǔn)時(shí)間(前臺(tái))和年月日時(shí)差為8個(gè)小時(shí),如果使用String得到的日期會(huì)少八小時(shí)?
(理由:世界時(shí)為標(biāo)準(zhǔn)。北京時(shí)間比世界時(shí)間早8小時(shí)標(biāo)準(zhǔn)時(shí)間)
如果后臺(tái)使用以下來接收前臺(tái)代碼
//修改前,會(huì)發(fā)現(xiàn)獲取的時(shí)間比預(yù)想的時(shí)間少八小時(shí) @TableField(exist = false) @ApiModelProperty(value = "上傳日期(起),查詢用") private String syncTimeStart;
應(yīng)該改為
//修改后:國際標(biāo)準(zhǔn)時(shí)間(前臺(tái))和年月日時(shí)差為8個(gè)小時(shí),如果使用String 得到的日期會(huì)少八小時(shí) @TableField(exist = false) @ApiModelProperty(value = "上傳日期(起),查詢用") private Date syncTimeStart;
req.setSyncTimeStart(StrUtils.dateTimeChange(req.getSyncTimeStart(),"00:00:00")); req.setSyncTimeEnd(StrUtils.dateTimeChange(req.getSyncTimeEnd(),"23:59:59"));
public static Date dateTimeChange (Date date, String time) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String formatStr = sdf.format(date);
formatStr = formatStr.substring(0,10)+" "+time;
Date changeDate = null;
try {
changeDate = sdf.parse(formatStr);
} catch (ParseException e) {
e.printStackTrace();
}
return changeDate;
}
當(dāng)然也可以使用兩個(gè)時(shí)間轉(zhuǎn)換方法解決文章來源:http://www.zghlxwxcb.cn/news/detail-460347.html
時(shí)間轉(zhuǎn)換文章來源地址http://www.zghlxwxcb.cn/news/detail-460347.html
到了這里,關(guān)于國際標(biāo)準(zhǔn)時(shí)間(前臺(tái))和年月日時(shí)差為8個(gè)小時(shí),如果使用String得到的日期會(huì)少八小時(shí)的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!