# xarray.CFTimeIndex.to_datetimeindex

#### CFTimeIndex.to_datetimeindex(unsafe=False, time_unit=None)[[source]](https://github.com/pydata/xarray/blob/main/xarray/coding/cftimeindex.py#L569-L654)

If possible, convert this index to a pandas.DatetimeIndex.

* **Parameters:**
  * **unsafe** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool)) – Flag to turn off calendar mismatch warnings (default `False`).
  * **time_unit** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Time resolution of resulting DatetimeIndex. Can be one of “s”,
    `"ms"`, `"us"`, or `"ns"` (default `"ns"`).
* **Returns:**
  [`pandas.DatetimeIndex`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DatetimeIndex.html#pandas.DatetimeIndex)
* **Raises:**
  [**ValueError**](https://docs.python.org/3/builtins/exceptions.html#ValueError) – If the CFTimeIndex contains dates that are not possible in the
      standard calendar or outside the range representable by the
      specified `time_unit`.
* **Warns:**
  **RuntimeWarning** – If converting from a non-standard calendar, or a Gregorian
  calendar with dates prior to the reform (1582-10-15).

#### WARNING
Note that for non-proleptic Gregorian calendars, this will change the
calendar type of the index. In that case the result of this method
should be used with caution.

### Examples

<div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesShowIframe('844c7ed3-a671-4550-a775-aaf45f99817b','3edfd2c6-2b91-4d03-9a2a-fb7ca74bf36d','28a21e36-0867-44be-a561-2fa7c2fa376e','../lite/tree/../notebooks/index.html?path=a1c45928_1dfb_44c4_a2a0_11c27ad59210.ipynb','None')">Try it in your browser!</button></div>
```pycon
>>> times = xr.date_range(
...     "2000", periods=2, calendar="gregorian", use_cftime=True
... )
>>> times
CFTimeIndex([2000-01-01 00:00:00, 2000-01-02 00:00:00],
            dtype='object', length=2, calendar='standard', freq=None)
>>> times.to_datetimeindex(time_unit="ns")
DatetimeIndex(['2000-01-01', '2000-01-02'], dtype='datetime64[ns]', freq=None)
```

<div id="28a21e36-0867-44be-a561-2fa7c2fa376e" class="try_examples_outer_iframe  hidden"><div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesHideIframe('844c7ed3-a671-4550-a775-aaf45f99817b','28a21e36-0867-44be-a561-2fa7c2fa376e')">Go Back</button><button class="try_examples_button" onclick="window.openInNewTab('844c7ed3-a671-4550-a775-aaf45f99817b','28a21e36-0867-44be-a561-2fa7c2fa376e')">Open In Tab</button></div><div id="3edfd2c6-2b91-4d03-9a2a-fb7ca74bf36d" class="jupyterlite_sphinx_iframe_container"></div></div><script>document.addEventListener("DOMContentLoaded", function() {window.loadTryExamplesConfig("../try_examples.json");});</script>
