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


Groups > comp.lang.python > #29362 > unrolled thread

utcnow

Started byNick the Gr33k <nikos.gr33k@gmail.com>
First post2012-09-17 07:25 +0300
Last post2012-09-17 14:48 +1000
Articles 2 — 2 participants

Back to article view | Back to comp.lang.python


Contents

  utcnow Nick the Gr33k <nikos.gr33k@gmail.com> - 2012-09-17 07:25 +0300
    Re: utcnow Ben Finney <ben+python@benfinney.id.au> - 2012-09-17 14:48 +1000

#29362 — utcnow

FromNick the Gr33k <nikos.gr33k@gmail.com>
Date2012-09-17 07:25 +0300
Subjectutcnow
Message-ID<mailman.822.1347855926.27098.python-list@python.org>
Hello is there a better way of writing this:

date = ( datetime.datetime.utcnow() + datetime.timedelta(hours=3) 
).strftime( '%y-%m-%d %H:%M:%S')

something like:

date = datetime.datetime.utcnow(hours=3).strftime( '%y-%m-%d %H:%M:%S')

i prefer it if it could be written as this.

Also what about dayligh savings time?

[toc] | [next] | [standalone]


#29364

FromBen Finney <ben+python@benfinney.id.au>
Date2012-09-17 14:48 +1000
Message-ID<87vcfdl0fq.fsf@benfinney.id.au>
In reply to#29362
Nick the Gr33k <nikos.gr33k@gmail.com> writes:

> Hello is there a better way of writing this:
>
> date = ( datetime.datetime.utcnow() + datetime.timedelta(hours=3)
> ).strftime( '%y-%m-%d %H:%M:%S')
>
> something like:
>
> date = datetime.datetime.utcnow(hours=3).strftime( '%y-%m-%d %H:%M:%S')
>
> i prefer it if it could be written as this.

Break long complicated statements into simpler statements. You might
need to get used to naming your intermediate results.

    now = datetime.datetime.utcnow()
    later = now + datetime.timedelta(hours=3)
    timestamp_text = later.strftime("%Y-%m-%d %H:%M:%S")

> Also what about dayligh savings time?

What about it? What has your reading of the ‘datetime’ module
documentation taught you?

-- 
 \        “Don't worry about people stealing your ideas. If your ideas |
  `\     are any good, you'll have to ram them down people's throats.” |
_o__)                                                    —Howard Aiken |
Ben Finney

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web