简体   繁体   English

python中的时间戳(年、月、日、小时、分钟)

[英]Timestamp in python (year,month,day,hour,minute)

Currently im using目前我正在使用

datetime.now()

The result im getting is for example我得到的结果是例如

datetime.datetime(2020, 2, 4, 10, 14, 20, 768814)

My goal is to get我的目标是得到

datetime.datetime(2020, 2, 4, 10, 14, 20)

You can use datetime.replace() :您可以使用datetime.replace()

>>> datetime.now().replace(microsecond=0)
datetime.datetime(2020, 2, 4, 9, 24, 32)

Its simple.这很简单。 If you don't want the microseconds, use below:如果您不想要微秒,请使用以下内容:

datetime.now().replace(microsecond=0)

Output ---> datetime.datetime(2020, 2, 4, 14, 53, 44)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 用Python解析年,月,日,时,分,秒 - Parsing year, month, day, hour, minute, second in Python 按分钟,小时,天,月和年分组? - groupby minute, hour, day, month, and year? 将时间戳转换为日,月,年和小时 - Convert timestamp to day, month, year and hour Python:如何以年月日时分秒格式转换谷歌位置时间戳? - Python: How to convert google location timestaMps in a year-month-day-hour-minute-seconds format? Python datetime - 在使用 strptime 获取日、月、年之后设置固定的小时和分钟 - Python datetime - setting fixed hour and minute after using strptime to get day,month,year Python Dataframe 将日期时间解析为年、月、日、时、分、秒的列 - Python Dataframe parse datetime into columns for year, month, day, hour, minute, second 如何在python中获取当前时间并分解为年、月、日、小时、分钟? - How to get current time in python and break up into year, month, day, hour, minute? 从当前日期时间中提取年、月、日、小时和分钟 - Extracting year, month, day, hour and minute from the current datetime 用python中的小时/分钟/秒将年/月/日添加到UNIX时间戳 - Add year/month/day to an UNIX timestamp with just hour/min/sec in python Python时间戳从日,月,年 - Python timestamp from day, month, year
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM