I have a netcdf file that gives me a time value of this:
numpy.datetime64('2019-10-28T18:00:00.000000000')
How can I change it into this "28 Oct 2019 18Z" and add it into a plt.title?
I have a netcdf file that gives me a time value of this:
numpy.datetime64('2019-10-28T18:00:00.000000000')
How can I change it into this "28 Oct 2019 18Z" and add it into a plt.title?
from datetime import datetime
import matplotlib.pyplot as plt
"""Convert datetime"""
timestring = '2019-10-28T18:00:00.000000000'[:26] #to make ist recognizable by strptime
new_dt_string = (datetime.strptime(timestring, '%Y-%m-%dT%H:%M:%S.%f'))
plt_dt_string = (datetime.strftime(new_dt_string, '%d %b %Y %HZ'))
print(plt_dt_string)
# output: 28 Oct 2019 18Z
"""Set plt title"""
plt.title('{}'.format(plt_dt_string))