Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #56697 > unrolled thread
| Started by | Joshua Landau <joshua@landau.ws> |
|---|---|
| First post | 2013-10-11 18:56 +0100 |
| Last post | 2013-10-11 18:56 +0100 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: datetime.timedelta.replace? Joshua Landau <joshua@landau.ws> - 2013-10-11 18:56 +0100
| From | Joshua Landau <joshua@landau.ws> |
|---|---|
| Date | 2013-10-11 18:56 +0100 |
| Subject | Re: datetime.timedelta.replace? |
| Message-ID | <mailman.1009.1381514226.18130.python-list@python.org> |
On 9 October 2013 16:15, Skip Montanaro <skip@pobox.com> wrote:
> Datetime objects have a replace method, but timedelta objects don't.
> If I take the diff of two datetimes and want to zero out the
> microseconds field, is there some way to do it more cleanly than this?
>
> delta = dt1 - dt2
> zero_delta = datetime.timedelta(days=delta.days, seconds=delta.seconds)
>
> I guess that's not bad, but replace() seems cleaner (or at least more
> congruent with datetime objects).
Maybe one of
delta - datetime.timedelta(0, 0, delta.microseconds)
or
delta - delta % datetime.timedelta(seconds=1)
is clearer.
Back to top | Article view | comp.lang.python
csiph-web