删除时间戳的时间部分
如何删除时间戳的时间部分?
例如,将 1310571061
转换为 1310565600
,这是纯日期时间戳。
How can I remove time part of a timestamp?
So for example turn 1310571061
to 1310565600
which is the plain date timestamp.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
那应该适合你。
That should do it for you.
如果您想要一个数学解决方案:
24 小时有 86,400 秒(这是典型一天的长度,但并非全部......请参阅 DST)。由于我们的时间戳采用 UTC,因此这应该不是问题。您可以将其除以一天中的秒数,去掉余数,然后再相乘。
In case you wanted a mathematical solution:
There are 86,400 seconds in 24 hours (which is the length of a typical day, but not all... see DST). Since our timestamps are in UTC, this shouldn't be a problem. You can divide that by the number of seconds in a day, drop the remainder, and multiply back out.
使用 DateTime 对象会很有帮助,并且还可以使代码更具可读性...
结果...
选择使用原始时间戳还是 DateTime 对象在很大程度上取决于实现需求,但一般来说 DateTime 对象会减少可能出现的混乱和错误还有很长的路要走,特别是在时区问题和夏令时问题方面。
Using a DateTime object can be helpful, and also can make the code more readable...
Result...
The choice of whether to use raw timestamps or DateTime objects will depend a lot on the implementation needs, but generally speaking DateTime objects will go a long way towards reducing confusion and errors that can crop up especially around Timezone issues and Daylight Saving Time issues.
尝试:
Try:
答案如下:“2003-02-19”
谢谢
The answer is like :"2003-02-19"
Thank You
你可以这样做:
You could do:
这就是我通常做的事情:
函数
strftime
会将your_timestamp
转换为不带时间部分的字符串。然后函数pd.to_datetime
会将其转换回不带时间分量的Timestamp
。This is what I usually do:
The function
strftime
will convertyour_timestamp
to a string without the time component. Then the functionpd.to_datetime
will convert it back to aTimestamp
without the time component.