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

formated local time

P: n/a
I have been trying to find appropriate way to do get local time in
"yyyy-mm-dd hh:mm:ss" format, but the best I got is this:
datetime.datetime.fromtimestamp(time.mktime(time.l ocaltime()))
It seems to me I'm missing a much simpler method, am I?

--
"Now the storm has passed over me
I'm left to drift on a dead calm sea
And watch her forever through the cracks in the beams
Nailed across the doorways of the bedrooms of my dreams"
Nov 15 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On Nov 15, 7:19 am, Nikola Skoric <nick-n...@net4u.hrwrote:
I have been trying to find appropriate way to do get local time in
"yyyy-mm-dd hh:mm:ss" format, but the best I got is this:
datetime.datetime.fromtimestamp(time.mktime(time.l ocaltime()))
It seems to me I'm missing a much simpler method, am I?

If you want the formatted string, you can use strftime:
>>time.strftime("%Y-%m-%d %H:%M:%S")
'2007-11-15 07:51:12'

--
Hope this helps,
Steven
Nov 15 '07 #2

P: n/a
You could use:

import time
time.strftime( "%Y-%m-%d %H:%M:%S" )
or
time.strftime( "%Y-%m-%d %H:%M:%S", time.localtime() )

Output:
'2007-11-15 11:02:34'

Both strftime calls are equivalent, in this case.
-----Original Message-----
From: py*****************************************@python .org
[mailto:py***************************************** @python.org
] On Behalf Of Nikola Skoric
Sent: Thursday, November 15, 2007 8:20 AM
To: py*********@python.org
Subject: formated local time

I have been trying to find appropriate way to do get local time in
"yyyy-mm-dd hh:mm:ss" format, but the best I got is this:
datetime.datetime.fromtimestamp(time.mktime(time.l ocaltime()))
It seems to me I'm missing a much simpler method, am I?

--
"Now the storm has passed over me
I'm left to drift on a dead calm sea
And watch her forever through the cracks in the beams
Nailed across the doorways of the bedrooms of my dreams"
--
http://mail.python.org/mailman/listinfo/python-list
Nov 15 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.