Python对2020-08-26T06:55:33.000Z
字符串的处理
可以先将
2020-08-26T06:55:33.000Z
转为datetime数据类型再转换为指定字符串格式的数据
_date = datetime.strptime(target_time, "%Y-%m-%dT%H:%M:%S.%fZ")
local_time = _date + timedelta(hours=8)
end_time = local_time.strftime("%Y-%m-%d %H:%M:%S")
return end_time
Python完整代码
"""
@File: new_adjust_time.py
@CreateTime: 2020/8/26 下午7:36
@Desc: 将字符串"2020-08-26T06:55:33.000Z"时间格式化
"""
from datetime import datetime, timedelta
def time_handler(target_time: str):
_date = datetime.strptime(target_time, "%Y-%m-%dT%H:%M:%S.%fZ")
local_time = _date + timedelta(hours=8)
end_time = local_time.strftime("%Y-%m-%d %H:%M:%S")
return end_time
if __name__ == '__main__':
start_time = "2020-08-26T06:55:33.000Z"
time_str = time_handler(start_time)
print(time_str)
go完整代码
package main
import (
"fmt"
"time"
)
func main() {
timeStr := "2020-09-01T02:43:57Z"
fmt.Println(GetTimestamp(timeStr))
}
func GetTimestamp(change string) int64 {
t, _ := time.Parse(time.RFC3339, change)
timeUint := t.In(time.Local).Unix()
return timeUint
}