Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #44218
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!news-out.readnews.com!transit4.readnews.com!panix!gordon |
|---|---|
| From | John Gordon <gordon@panix.com> |
| Newsgroups | comp.lang.python |
| Subject | Re: datetime.strptime() not padding 0's |
| Date | Tue, 23 Apr 2013 21:38:18 +0000 (UTC) |
| Organization | PANIX Public Access Internet and UNIX, NYC |
| Lines | 31 |
| Message-ID | <kl6v0a$di$1@reader1.panix.com> (permalink) |
| References | <mailman.995.1366751728.3114.python-list@python.org> |
| NNTP-Posting-Host | panix3.panix.com |
| X-Trace | reader1.panix.com 1366753098 434 166.84.1.3 (23 Apr 2013 21:38:18 GMT) |
| X-Complaints-To | abuse@panix.com |
| NNTP-Posting-Date | Tue, 23 Apr 2013 21:38:18 +0000 (UTC) |
| User-Agent | nn/6.7.3 |
| Xref | csiph.com comp.lang.python:44218 |
Show key headers only | View raw
In <mailman.995.1366751728.3114.python-list@python.org> Rodrick Brown <rodrick.brown@gmail.com> writes:
> I thought I read some where that strptime() will pad 0's for day's for some
> reason this isnt working for me and I'm wondering if i'm doing something
> wrong.
> >>> from datetime import datetime
> >>> dt = datetime.strptime('Apr 9 2013', '%b %d %Y')
> >>> dt.day
> 9
> How can I get strptime to run 09? instead of 9
dt.day is just an integer. If you want to print it with zero padding,
use a format string:
>>> n = 9
>>> print n
9
>>> print '%02d' % n
09
or for python 3:
>>> print("{0:02d}".format(n))
09
--
John Gordon A is for Amy, who fell down the stairs
gordon@panix.com B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
datetime.strptime() not padding 0's Rodrick Brown <rodrick.brown@gmail.com> - 2013-04-23 17:14 -0400 Re: datetime.strptime() not padding 0's John Gordon <gordon@panix.com> - 2013-04-23 21:38 +0000
csiph-web