立即注册 登录
气象家园 返回首页

主啊的个人空间 https://bbs.06climate.com/?69999 [收藏] [复制] [分享] [RSS]

日志

python nc数据世界时间转换北京时间,欢迎讨论啊,写的菜

已有 96 次阅读2023-6-13 16:45 |个人分类:python


import xarray as xr
import netCDF4 as nc
import datetime as dt
import pandas as pd
from datetime import datetime, timedelta

timefile = 'E:/xinzheng2021-2022/2021year01-03day0-23h.nc'
data = xr.open_dataset(timefile)
#
# print(data["time"]-28800)
# print("**"*60)
# print(data.time.dt.strftime("%Y-%m-%d %H:%M:%S"))


# print(data.time + dt.timedelta(hours=8))


# data["time"] = data["time"] + dt.timedelta(hours=8)
# print("*-"*96)
# print(data.time)

# print(data["time"].values)

f = []

for i in data["time"].values:
print("before",i)
# print(type(i))
# print(i - timedelta(hours=8))
# print(str(i)[0:-10])
i = dt.datetime.strptime(str(i)[0:-10], '%Y-%m-%dT%H:%M:%S')
i = i + dt.timedelta(hours=8)
print("after")
print(i)
i = i.strftime('%Y-%m-%dT%H:%M:%S')
f.append(i)

print("*"*60)
print(f)

time = f
tsc = data.Temperature_height_above_ground
lat = tsc.lat
lon = tsc.lon
tt = xr.DataArray(tsc, coords=[time,lat,lon], dims=['time','lat','lon'])
print(tt.time)


# https://wenku.csdn.net/answer/8ea5238234e446ab975b2bb86714d8e9
# https://www.jianshu.com/p/79f5df5ec359

# data.time.dt.strptime("%Y-%m-%dT%H:%M:%S.%fZ")

# from datetime import datetime, timedelta
#
# now_time = datetime.now()
# utc_time = now_time - timedelta(hours=8) # UTC只是比北京时间提前了8个小时
# utc_time = utc_time.strftime("%Y-%m-%dT%H:%M:%SZ") # 转换成Aliyun要求的传参格式...
# print(utc_time)






评论 (0 个评论)

facelist doodle 涂鸦板

您需要登录后才可以评论 登录 | 立即注册

Copyright ©2011-2014 bbs.06climate.com All Rights Reserved.  Powered by Discuz! (京ICP-10201084)

本站信息均由会员发表,不代表气象家园立场,禁止在本站发表与国家法律相抵触言论

返回顶部