Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #109131

Re: Format a timedelta object

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From Zachary Ware <zachary.ware+pylist@gmail.com>
Newsgroups comp.lang.python
Subject Re: Format a timedelta object
Date Thu, 26 May 2016 00:28:40 -0500
Lines 20
Sender zachary.ware@gmail.com
Message-ID <mailman.0.1464240542.2277.python-list@python.org> (permalink)
References <574686cc$0$1584$c3e8da3$5496439d@news.astraweb.com> <CAKJDb-Ng+o-QQAwkr7VkEXTxYnMGQhxS7VdMs6nTLg8_0fwBLQ@mail.gmail.com>
Reply-To python-list@python.org
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8
X-Trace news.uni-berlin.de ETN+NsW4CXR1eO2cK/8c8wmQymPAF68n4T0SLqFXuRbA==
Return-Path <zachary.ware@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.023
X-Spam-Evidence '*H*': 0.95; '*S*': 0.00; 'reminded': 0.09; 'properly': 0.15; 'thu,': 0.15; '2016': 0.16; 'forty': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'subject:object': 0.16; 'wrote:': 0.16; 'sender:addr:gmail.com': 0.18; '>>>': 0.20; 'to:name:python-list@python.org': 0.20; 'hours,': 0.22; 'trying': 0.22; 'am,': 0.23; 'plain': 0.24; 'header:In-Reply-To:1': 0.24; 'figure': 0.27; 'message-id:@mail.gmail.com': 0.27; 'object,': 0.27; 'str': 0.29; "d'aprano": 0.33; 'steven': 0.33; 'this?': 0.34; 'skip:d 20': 0.34; 'gives': 0.35; 'received:google.com': 0.35; 'too': 0.36; 'there': 0.36; 'received:209.85': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'being': 0.37; 'display': 0.37; 'received:209.85.213': 0.37; 'received:209': 0.38; 'format': 0.39; 'to:addr:python.org': 0.40; 'header:Reply- To:1': 0.67; 'reply-to:no real name:2**0': 0.71; '26,': 0.72; 'reply-to:addr:python.org': 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:reply-to:sender:in-reply-to:references:from:date :message-id:subject:to; bh=IXv+RmK0n1j2E80NBxnR+JTjiaYAXVPVRSGSNBDcPtY=; b=LM7NCwQkN9fIAlKpZ6FY4rywy9ljuUuug/ckXSG4/gf+Ef8DA0ruHD9jd/kg3RTFwE aTG2KbaOxVE9KQlVzybdZd8JhnD+DIPN18NNgow+vqAbc3wFqQoCV77sJuMKoK5JVrL5 WAn0cLvG+B4xrySA5ADOt6TZKw6yhL1DmTEyr754EA5D+H5slMKuWEe5WdV6AUXoXkuy M9XUgxy/PG4NeJLAtIiSI6KurMeifG20R8hAxZKT4o4XvQCh6fIWKl8IbCPnigH/9r+5 wx9SLlO9pJXdGISVeIkPdjdHTgkc9rE50rSq3LPgCh4NUHcvADqiqmmWX8ISPU5ZDt80 TLzw==
X-Google-DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:reply-to:sender:in-reply-to :references:from:date:message-id:subject:to; bh=IXv+RmK0n1j2E80NBxnR+JTjiaYAXVPVRSGSNBDcPtY=; b=IF9f2mjwUAza1X4ihXmPl1zlxHdfg7kxriTWx+Xdvr3R0l+KLgivDyCI4hq0p++QV6 qsIwPvkS1ImBPF3f0kgtSa9ff7Kgrlb/0wFnJ9/6UBTKJ6Y5DS+jk5lAcol5q8OejqPN 2lNBz3SSsKxrnusbPpOQOVxwWDlHPhGEuCNtosOyIYBFHMqLdCps7OS1tJWhHuRrP5aH lXiDFmpbSRdwj5G5EREq2pzVI5uWoprZh0W5/WP/8NvUQ85utlHdaIymT/Ci1F57zGsO VlcuNqQ2GuJRjMAgtS3nxDfT0YCdEtTX6tZIjWTCyu3ERMqmYqmOCuKe4+Tc0iJVJSJ4 XXMQ==
X-Gm-Message-State ALyK8tL5gOks4pe4IYrX00SLOpwzGpQmBp7qogV66B778xelBjUKtJxxJKkGvbf1XAxiLsHOEcMyui+p3E7j5w==
X-Received by 10.31.33.143 with SMTP id h137mr4801477vkh.59.1464240539398; Wed, 25 May 2016 22:28:59 -0700 (PDT)
In-Reply-To <574686cc$0$1584$c3e8da3$5496439d@news.astraweb.com>
X-Google-Sender-Auth pP4FwdCqnNiC52XFz6ef5Emc-64
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.22
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID <CAKJDb-Ng+o-QQAwkr7VkEXTxYnMGQhxS7VdMs6nTLg8_0fwBLQ@mail.gmail.com>
X-Mailman-Original-References <574686cc$0$1584$c3e8da3$5496439d@news.astraweb.com>
Xref csiph.com comp.lang.python:109131

Show key headers only | View raw


On Thu, May 26, 2016 at 12:16 AM, Steven D'Aprano
<steve+comp.lang.python@pearwood.info> wrote:
> I have a timedelta object, and I want to display it in a nice human-readable
> format like 03:45:17 for "three hours, forty five minutes, 17 seconds".
>
> Is there a standard way to do this?

   >>> timedelta(100)
   datetime.timedelta(100)
   >>> str(timedelta(seconds=100))
   '0:01:40'
   >>> str(timedelta(hours=100))
   '4 days, 4:00:00'

(I recently spent *way* too long trying to figure out how to properly
format the thing before being reminded that a plain str call gives
exactly what I was after.)

-- 
Zach

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Format a timedelta object Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2016-05-26 15:16 +1000
  Re: Format a timedelta object Zachary Ware <zachary.ware+pylist@gmail.com> - 2016-05-26 00:28 -0500
    Re: Format a timedelta object Steven D'Aprano <steve@pearwood.info> - 2016-05-28 02:21 +1000
      Re: Format a timedelta object Zachary Ware <zachary.ware+pylist@gmail.com> - 2016-05-27 11:34 -0500
      Re: Format a timedelta object Pete Forman <petef4+usenet@gmail.com> - 2016-05-27 21:41 +0100
  Re: Format a timedelta object Marko Rauhamaa <marko@pacujo.net> - 2016-05-26 08:43 +0300

csiph-web