<small id='Z3AKy'></small><noframes id='Z3AKy'>

  1. <i id='Z3AKy'><tr id='Z3AKy'><dt id='Z3AKy'><q id='Z3AKy'><span id='Z3AKy'><b id='Z3AKy'><form id='Z3AKy'><ins id='Z3AKy'></ins><ul id='Z3AKy'></ul><sub id='Z3AKy'></sub></form><legend id='Z3AKy'></legend><bdo id='Z3AKy'><pre id='Z3AKy'><center id='Z3AKy'></center></pre></bdo></b><th id='Z3AKy'></th></span></q></dt></tr></i><div id='Z3AKy'><tfoot id='Z3AKy'></tfoot><dl id='Z3AKy'><fieldset id='Z3AKy'></fieldset></dl></div>

  2. <legend id='Z3AKy'><style id='Z3AKy'><dir id='Z3AKy'><q id='Z3AKy'></q></dir></style></legend>
    • <bdo id='Z3AKy'></bdo><ul id='Z3AKy'></ul>

      <tfoot id='Z3AKy'></tfoot>
    1. 在列表中查找最旧/最年轻的日期时间对象

      时间:2023-11-08
        <bdo id='x8ozQ'></bdo><ul id='x8ozQ'></ul>

              <tbody id='x8ozQ'></tbody>

              <small id='x8ozQ'></small><noframes id='x8ozQ'>

                <i id='x8ozQ'><tr id='x8ozQ'><dt id='x8ozQ'><q id='x8ozQ'><span id='x8ozQ'><b id='x8ozQ'><form id='x8ozQ'><ins id='x8ozQ'></ins><ul id='x8ozQ'></ul><sub id='x8ozQ'></sub></form><legend id='x8ozQ'></legend><bdo id='x8ozQ'><pre id='x8ozQ'><center id='x8ozQ'></center></pre></bdo></b><th id='x8ozQ'></th></span></q></dt></tr></i><div id='x8ozQ'><tfoot id='x8ozQ'></tfoot><dl id='x8ozQ'><fieldset id='x8ozQ'></fieldset></dl></div>
                <tfoot id='x8ozQ'></tfoot>

                <legend id='x8ozQ'><style id='x8ozQ'><dir id='x8ozQ'><q id='x8ozQ'></q></dir></style></legend>

              1. 本文介绍了在列表中查找最旧/最年轻的日期时间对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                I've got a list of datetime objects, and I want to find the oldest or youngest one. Some of these dates might be in the future.

                from datetime import datetime
                
                datetime_list = [
                    datetime(2009, 10, 12, 10, 10),
                    datetime(2010, 10, 12, 10, 10),
                    datetime(2010, 10, 12, 10, 10),
                    datetime(2011, 10, 12, 10, 10), #future
                    datetime(2012, 10, 12, 10, 10), #future
                ]
                

                What's the most optimal way to do so? I was thinking of comparing datetime.now() to each one of those.

                解决方案

                Oldest:

                oldest = min(datetimes)
                

                Youngest before now:

                now = datetime.datetime.now(pytz.utc)
                youngest = max(dt for dt in datetimes if dt < now)
                

                这篇关于在列表中查找最旧/最年轻的日期时间对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:如何判断一个日期是否在另外两个日期之间? 下一篇:使用 Python 比较 2 个 excel 文件

                相关文章

              2. <small id='LRpul'></small><noframes id='LRpul'>

                <legend id='LRpul'><style id='LRpul'><dir id='LRpul'><q id='LRpul'></q></dir></style></legend>
                • <bdo id='LRpul'></bdo><ul id='LRpul'></ul>
              3. <tfoot id='LRpul'></tfoot>
                  <i id='LRpul'><tr id='LRpul'><dt id='LRpul'><q id='LRpul'><span id='LRpul'><b id='LRpul'><form id='LRpul'><ins id='LRpul'></ins><ul id='LRpul'></ul><sub id='LRpul'></sub></form><legend id='LRpul'></legend><bdo id='LRpul'><pre id='LRpul'><center id='LRpul'></center></pre></bdo></b><th id='LRpul'></th></span></q></dt></tr></i><div id='LRpul'><tfoot id='LRpul'></tfoot><dl id='LRpul'><fieldset id='LRpul'></fieldset></dl></div>