# xarray.CFTimeIndex.to_datetimeindex

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

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('bc6c75f9-02f2-4fc5-aa69-d64ba5f6c681','4619b678-c1c6-404a-96af-372d4a9cac19','710d95e5-471d-460b-a7fe-cbb947cfb974','../lite/tree/../notebooks/index.html?path=0739eae5_2e96_41d7_b98d_420425a390b4.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="710d95e5-471d-460b-a7fe-cbb947cfb974" class="try_examples_outer_iframe  hidden"><div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesHideIframe('bc6c75f9-02f2-4fc5-aa69-d64ba5f6c681','710d95e5-471d-460b-a7fe-cbb947cfb974')">Go Back</button><button class="try_examples_button" onclick="window.openInNewTab('bc6c75f9-02f2-4fc5-aa69-d64ba5f6c681','710d95e5-471d-460b-a7fe-cbb947cfb974')">Open In Tab</button></div><div id="4619b678-c1c6-404a-96af-372d4a9cac19" class="jupyterlite_sphinx_iframe_container"></div></div><script>document.addEventListener("DOMContentLoaded", function() {window.loadTryExamplesConfig("../try_examples.json");});</script>
