By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,199 Members | 1,064 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,199 IT Pros & Developers. It's quick & easy.

Time functions

P: n/a

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
Share this Question
Share on Google+
5 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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.