简体   繁体   English

如何在使用时间增量时只输出天数(没有小时、分钟和秒)?

[英]How to only output the days (without hours, minutes, and seconds) while using time delta?

I have a function:我有一个功能:

def diffDate(YYYY,MM,DD):
    tgl = date(YYYY,MM,DD)
    skrg = datetime.date(datetime.now())
    if tgl <= skrg:
        diffDate = skrg - tgl
    elif tgl >= skrg:
        diffDate = tgl - skrg
    return diffDate

The output will be "x days, 0:00:00".输出将为“x 天,0:00:00”。 How to only output the days without the hours, minutes, and seconds?如何只输出没有小时、分钟和秒的天数? And can I multiple the day difference with integer without taking the 'days' ?我可以在不取“天”的情况下用整数乘以天数差异吗? *Sorry for my bad english *对不起,我的英语不好

You can do multiple steps in one:您可以合二为一地执行多个步骤:

datetime import date

def absoluteDaysToNow(yyyy, mm, dd):
  delta = date.today() - date(yyyy, mm, dd)
  return abs( delta.days )

See: python docs, built-in function abs() , date example: days difference请参阅:python 文档,内置函数 abs()日期示例:天数差异

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

相关问题 Pandas 到时间增量只有小时分钟和秒 - Pandas to time delta with only hours minutes and seconds 如何将以天、小时、分钟和秒为单位的时间转换为仅秒? - How to convert time in days, hours, minutes, and seconds to only seconds? Python 以天、小时、分钟、秒表示的经过时间 - Python Elapsed Time as Days, Hours, Minutes, Seconds 如何在 Python 中将天转换为小时、分钟和秒 - How transform days to hours, minutes and seconds in Python Python时间格式为=&gt; [天:小时:分钟:秒]至秒 - Python time in format => [days:hours:minutes:seconds] to seconds 如何仅获取没有小时分钟和秒的日期时间 python pandas - How to only get datetime without hours minutes and seconds python pandas 在 Pandas 中,如何使用 Regex 将人类可读的时间格式分解为不同的单位,如天、小时、分钟和秒? - In Pandas, how do I breakdown human readable format of time into different units like days, hours, minutes, and seconds using Regex? 将秒转换为天,小时,分钟和秒 - Converting Seconds into days, hours, minutes, and seconds 在 Python 中将秒转换为天、小时、分钟和秒 - Converting seconds into days, hours, minutes & seconds in Python 如何在Python / Django中将此持续时间转换为天/小时/分钟/秒? - How to convert this duration into days/hours/minutes/seconds in Python/Django?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM