title: Writing time NetCDF file in python using NetCDF4
body: <p>I am trying to write a netcdf file using Netcdf4 library. My netcdf file has time, lat, lon and value variables. The time is monthly (i.e. 12 time values from 1/1/2000 to 12/1/2000).</p>
  <p>I cannot write the time variable in the netcdf, my code is as follows:</p>
  <pre><code>import netCDF4 as nc
  dsn = nc.Dataset(filename,'w', format='NETCDF4')
  time = dsn.createDimension(&quot;time&quot;, None)
  latd = dsn.createDimension(&quot;lat&quot;, len(lat))
  lond = dsn.createDimension(&quot;lon&quot;, len(lon))
  
  timev = dsn.createVariable(&quot;time&quot;, 'f4', ('time',))
  latv = dsn.createVariable(&quot;lat&quot;, 'f4', ('lat',))
  lonv = dsn.createVariable(&quot;lon&quot;, 'f 4', ('lon',))
  value = dsn.createVariable(&quot;irr_req&quot;, 'f4', ('time', 'lat', 'lon',))
  value.units = 'mm/month'
  
  latv[:] = np.array(lat)  ## lat is an array with length 296 and lon witg 690
  lonv[:] = np.array(lon)
  
  ## I am using relativedelta to write the monthly time data because I do not know another method-
  
  from dateutil.relativedelta import * 
  
  time =[datetime.datetime(2000, 1, 1) + relativedelta(months = month)
           for month in range(12)]
  
  timev[:] = nc.date2num(time, &quot;months since 2000-01-01 00:00&quot; , calendar='360_day')
  
  </code></pre>
  <p>By doing this, I get the following error:
  <code>RuntimeError: NetCDF: Not a valid ID</code></p>
  <p>How can I write the time values? I am also ok with writing integers from 1 to 12 for months instead of the datetime variable.</p>