[python-win32] datetime.datetime.now(tz=WHAT?????)

Jens B. Jorgensen jens.jorgensen at tallan.com
Wed Jun 2 18:59:19 EDT 2004


My first question would be: do you really need the tz? Why not just put 
in the UTC time and put +0000 in for the timezone info. In fact, 
documentation under the built-in time module demonstrates:

> Here is an example, a format for dates compatible with that specified 
> in the RFC 2822 <http://www.faqs.org/rfcs/rfc2822.html> Internet email 
> standard. ^6.1 <#foot25196>
>
>>>> from time import gmtime, strftime
>>>> strftime("%a, %d %b %Y %H:%M:%S +0000", gmtime())
>'Thu, 28 Jun 2001 14:17:15 +0000'
>  
>
> Additional directives may be supported on certain platforms, but only 
> the ones listed here have a meaning standardized by ANSI C.
>


Vernon Cole wrote:

> I suppose that there is an easy answer to this question... if I only 
> could find the correct document to read.
> Environment: Python 2.3.4    on  Windows2000
> Application:  Trying to construct a date string for use by 
> smtplib.sendmail()
>    ... It should look like: "27 Aug 2020 09:32:31 MDT"
>    ... or "27 Aug 2020 09:32:31 +0700"
> What I have tried (latest vain attempt):
>    import datetime
>    date = datetime.datetime.strftime(
>        datetime.datetime.now(),
>        '%d %b %Y %H:%M:%S %z')
>    print date
>
> The date prints WITHOUT TIME ZONE -- as documented.
> In order to print the timezone I must provide an object of type tzinfo 
> to supply to
> datetime.datetime.now(tz= ????)  .
>
> Questions: 1)    I could hard code the timezone, but the documents 
> show only use of tz=None, which is the not helpful.  How do I create 
> an instance of a tzinfo for a specific time zone?
>
> 2)    Windows already knows my timezone.   How do I get it so that I 
> can plug it in?
>
> 3) Am I trying a completly wrong approach and should be using some 
> other module?
>
> ----------
> Vernon
>
>
>
> _______________________________________________
> Python-win32 mailing list
> Python-win32 at python.org
> http://mail.python.org/mailman/listinfo/python-win32



-- 
Jens B. Jorgensen
jens.jorgensen at tallan.com

"With a focused commitment to our clients and our people, we deliver value through customized technology solutions"  




More information about the Python-win32 mailing list