formated local time

Adam Pletcher adam at volition-inc.com
Thu Nov 15 11:12:11 EST 2007


datetime also has the strftime method:

import datetime
datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')

- Adam

> -----Original Message-----
> From: python-list-bounces+adam=volition-inc.com at python.org
> [mailto:python-list-bounces+adam=volition-inc.com at python.org] On
Behalf
> Of attn.steven.kuo at gmail.com
> Sent: Thursday, November 15, 2007 9:56 AM
> To: python-list at python.org
> Subject: Re: formated local time
> 
> On Nov 15, 7:19 am, Nikola Skoric <nick-n... at net4u.hr> wrote:
> > 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.localtime()))
> > 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
> --
> http://mail.python.org/mailman/listinfo/python-list



More information about the Python-list mailing list