如果我得到 UTC 日期低于 2012-04-17T15:40+05:00 ====结果我期待======>>> 2012-04-17T15:40+08:00我不想转换我只想替换时区偏移量
1 回答

翻过高山走不出你
TA贡献1875条经验 获得超3个赞
如果你在谈论字符串操作,你可以这样做:
function replaceTimezoneOffset(dateTime: string, newOffset: string): string {
return `${dateTime.split('+')[0]}${newOffset}`;
}
你可以像这样使用它:
const newDate = replaceTimezoneOffset('2012-04-17T15:40+05:00', '+08:00');
console.log({newDate}); // {newDate: '2012-04-17T15:40+08:00'}
添加回答
举报
0/150
提交
取消