Home > database >  How to convert days to datetime where time origin is 1-JAN-0000 00:00:00?
How to convert days to datetime where time origin is 1-JAN-0000 00:00:00?

Time:10-29

I have a netCDF dataset which includes coordinates of 'time' and 'depth'. The time coordinate has data stored in the format of days, where origin time is 'JAN1-0000 00:00:00' (Image for the dataset is attached below). I want to know how to convert those days to correct datetime format ?enter image description here

Thanks in advance!

CodePudding user response:

There are 719528 days between year 0 and epoch (1970-01-01).

You can subtract those days and use to_datetime with days as unit:

time = np.array([731957.5, 731958.5])

out = pd.to_datetime(time-719528, unit='d')

output: DatetimeIndex(['2004-01-12 12:00:00', '2004-01-13 12:00:00'], dtype='datetime64[ns]', freq=None)

  • Related