# 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('e2400f35-d461-4332-8f7e-031809fa6491','07a4f6c6-43a1-4475-9665-cbcde2b3ce84','9f81d9c2-aa1e-4346-99d3-ad90ebb03a0a','../lite/tree/../notebooks/index.html?path=df439fb2_bdff_43b9_8a8d_7cedfae02b39.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="9f81d9c2-aa1e-4346-99d3-ad90ebb03a0a" class="try_examples_outer_iframe  hidden"><div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesHideIframe('e2400f35-d461-4332-8f7e-031809fa6491','9f81d9c2-aa1e-4346-99d3-ad90ebb03a0a')">Go Back</button><button class="try_examples_button" onclick="window.openInNewTab('e2400f35-d461-4332-8f7e-031809fa6491','9f81d9c2-aa1e-4346-99d3-ad90ebb03a0a')">Open In Tab</button></div><div id="07a4f6c6-43a1-4475-9665-cbcde2b3ce84" class="jupyterlite_sphinx_iframe_container"></div></div><script>document.addEventListener("DOMContentLoaded", function() {window.loadTryExamplesConfig("../try_examples.json");});</script>
