- 积分
- 22699
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2011-7-23
- 最后登录
- 1970-1-1
|

楼主 |
发表于 2019-6-10 03:22:14
|
显示全部楼层
网上找到的代码,你可以试一下
# ***** How to get time value into Python DateTIme Objects *****
import datetime # Python standard library datetime module
from netCDF4 import Dataset,netcdftime,num2date # http://unidata.github.io/netcdf4-python/
file_in = Dataset("file.nc","r",format="NETCDF4")
tname = "time_variable_name"
nctime = file_in.variables[tname][:] # get values
t_unit = file_in.variables[tname].units # get unit "days since 1950-01-01T00:00:00Z"
t_cal = file_in.variables[tname].calendar
tvalue = num2date(nctime,units = t_unit,calendar = t_cal)
str_time = [i.strftime("%Y-%m-%d %H:%M") for i in tvalue] # to display dates as string
# ***** End ***** |
|