470,624 Members | 2,538 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,624 developers. It's quick & easy.

Time functions


I wish to generate a datetime string that has the following format.
'05/02/2007 12:46'. The leading zeros are required.

I found '14.2 time' in the library reference and have pulled in
localtime. Are there any formatting functions available or do I need
to make my own? Perhaps there is something similar to C's printf
formatting.

Thanks,

jvh (whose newbieism is most glaring)

May 2 '07 #1
5 1233
On May 2, 12:00 pm, HMS Surprise <j...@datavoiceint.comwrote:
I wish to generate a datetime string that has the following format.
'05/02/2007 12:46'. The leading zeros are required.

I found '14.2 time' in the library reference and have pulled in
localtime. Are there any formatting functions available or do I need
to make my own? Perhaps there is something similar to C's printf
formatting.

Thanks,

jvh (whose newbieism is most glaring)
Oops, it appears I overlooked strftime.

Regrets,

jvh

May 2 '07 #2
In <11*********************@o5g2000hsb.googlegroups.c om>, HMS Surprise
wrote:
I wish to generate a datetime string that has the following format.
'05/02/2007 12:46'. The leading zeros are required.

I found '14.2 time' in the library reference and have pulled in
localtime. Are there any formatting functions available or do I need
to make my own? Perhaps there is something similar to C's printf
formatting.
You mean like `time.strftime()`!? :-)

Ciao,
Marc 'BlackJack' Rintsch
May 2 '07 #3
On May 2, 12:03 pm, Marc 'BlackJack' Rintsch <bj_...@gmx.netwrote:
In <1178125256.640115.26...@o5g2000hsb.googlegroups.c om>, HMS Surprise
wrote:
I wish to generate a datetime string that has the following format.
'05/02/2007 12:46'. The leading zeros are required.
I found '14.2 time' in the library reference and have pulled in
localtime. Are there any formatting functions available or do I need
to make my own? Perhaps there is something similar to C's printf
formatting.

You mean like `time.strftime()`!? :-)

Ciao,
Marc 'BlackJack' Rintsch
Thanks for posting.

I think I have an import misconception.

I use
import from time localtime, strftime
t = strftime('%m/%d/%Y %H:%M', localtime())

This works. How would one use it with the module name pre-pended?

thanx,
jvh

May 2 '07 #4
On May 2, 10:21 am, HMS Surprise <j...@datavoiceint.comwrote:
On May 2, 12:03 pm, Marc 'BlackJack' Rintsch <bj_...@gmx.netwrote:
In <1178125256.640115.26...@o5g2000hsb.googlegroups.c om>, HMS Surprise
wrote:
I wish to generate a datetime string that has the following format.
'05/02/2007 12:46'. The leading zeros are required.
I found '14.2 time' in the library reference and have pulled in
localtime. Are there any formatting functions available or do I need
to make my own? Perhaps there is something similar to C's printf
formatting.
You mean like `time.strftime()`!? :-)
Ciao,
Marc 'BlackJack' Rintsch

Thanks for posting.

I think I have an import misconception.

I use
import from time localtime, strftime
t = strftime('%m/%d/%Y %H:%M', localtime())

This works. How would one use it with the module name pre-pended?

thanx,
jvh
I would think that what you have written there shouldn't work at
all...

it would need to be:

Expand|Select|Wrap|Line Numbers
  1. from time import localtime, strftime
  2.  
to use the prepended module name just do this instead:

Expand|Select|Wrap|Line Numbers
  1. import time
  2. t = time.strftime('%m/%d/%Y %H:%M', time.localtime())
  3.  
May 2 '07 #5
On 2007-05-02, Matimus <mc******@gmail.comwrote:
>I think I have an import misconception.

I use
import from time localtime, strftime
t = strftime('%m/%d/%Y %H:%M', localtime())

This works. How would one use it with the module name pre-pended?

I would think that what you have written there shouldn't work at
all...
It doesn't.
it would need to be:

Expand|Select|Wrap|Line Numbers
  1. from time import localtime, strftime
  2.  

to use the prepended module name just do this instead:

Expand|Select|Wrap|Line Numbers
  1. import time
  2. t = time.strftime('%m/%d/%Y %H:%M', time.localtime())
  3.  
or just this

t = time.strftime('%m/%d/%Y %H:%M')

time.strftime() has used the localtime() value by default for
a while now.
--
Grant Edwards grante Yow! There's enough money
at here to buy 5000 cans of
visi.com Noodle-Roni!
May 2 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Rick | last post: by
18 posts views Thread by bart_nessux | last post: by
11 posts views Thread by Bryant Huang | last post: by
3 posts views Thread by Luis Pedro | last post: by
17 posts views Thread by newbiecpp | last post: by
5 posts views Thread by RICHARD BROMBERG | last post: by
7 posts views Thread by dc | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.