Skip to content

ENH: Timestamp/DTI. to epoch time #14772

Open
@jreback

Description

@jreback

add a .to_epoch(unit='s') method to Timestamp and DatetimeIndex that returns the epoch for that unit. I think would default this to s as that seems pretty common, but allow any of our units.

In [19]: s = Series(pd.date_range('20160101',periods=3))

In [20]: s
Out[20]: 
0   2016-01-01
1   2016-01-02
2   2016-01-03
dtype: datetime64[ns]

In [21]: ((s-Timestamp(0)) / Timedelta('1s')).astype('i8')
Out[21]: 
0    1451606400
1    1451692800
2    1451779200
dtype: int64

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions