Path: csiph.com!usenet.pasdenom.info!dedibox.gegeweb.org!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.007 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'configure': 0.04; 'locale': 0.07; 'sep': 0.09; 'span': 0.09; 'charset:iso-8859-7': 0.15; 'properly': 0.15; 'sat,': 0.15; 'from:addr:mrabarnett.plus.com': 0.16; 'from:addr:python': 0.16; 'from:name:mrab': 0.16; 'help?': 0.16; 'message- id:@mrabarnett.plus.com': 0.16; 'subject:issue': 0.16; 'utc': 0.16; 'wrote:': 0.17; 'pointed': 0.17; 'skip:p 30': 0.20; 'variable': 0.20; 'otherwise,': 0.20; 'import': 0.21; 'of.': 0.22; 'skip:% 10': 0.22; '15,': 0.23; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'setting': 0.26; 'values': 0.26; 'am,': 0.27; 'correct': 0.28; 'chris': 0.28; 'didnt': 0.29; 'received:192.168.1.3': 0.29; 'this.': 0.29; 'to:addr:python- list': 0.33; 'skip:d 20': 0.34; 'jason': 0.35; 'skip:l 30': 0.35; 'too.': 0.35; 'but': 0.36; 'should': 0.36; 'enough': 0.36; 'does': 0.37; 'subject:: ': 0.38; 'some': 0.38; 'several': 0.39; 'to:addr:python.org': 0.39; 'received:192': 0.39; 'where': 0.40; 'received:192.168': 0.40; 'matter': 0.61; 'save': 0.61; 'wide': 0.62; 'hours': 0.66; 'header:Reply-To:1': 0.68; 'reply-to:no real name:2**0': 0.72; 'communities,': 0.84; 'greek': 0.84; 'reply- to:addr:python.org': 0.84 X-CM-Score: 0.00 X-CNFS-Analysis: v=2.0 cv=W6e6pGqk c=1 sm=1 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=AAvI7MrX_rgA:10 a=ihvODaAuJD4A:10 a=OUOv7kDek9cA:10 a=E_FQspuQcigA:10 a=EBOSESyhAAAA:8 a=8AHkEIZyAAAA:8 a=MDrHMdyo4tAA:10 a=pGLkceISAAAA:8 a=IT4jJZXxXMvu5EAKQlgA:9 a=o3X3QV6JOaEA:10 a=MSl-tDqOz04A:10 a=0nF1XD0wxitMEM03M9B4ZQ==:117 X-AUTH: mrabarnett:2500 Date: Sat, 15 Sep 2012 21:28:27 +0100 From: MRAB User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:15.0) Gecko/20120907 Thunderbird/15.0.1 MIME-Version: 1.0 To: python-list@python.org Subject: Re: datetime issue References: <52847c35-388c-4758-b72d-1d1859b788a3@googlegroups.com> In-Reply-To: <52847c35-388c-4758-b72d-1d1859b788a3@googlegroups.com> Content-Type: text/plain; charset=ISO-8859-7; format=flowed Content-Transfer-Encoding: 8bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: python-list@python.org List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 46 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1347740899 news.xs4all.nl 6968 [2001:888:2000:d::a6]:34871 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:29275 On 2012-09-15 20:26, Νικόλαος Κούρας wrote: > Τη Σάββατο, 15 Σεπτεμβρίου 2012 10:05:49 μ.μ. UTC+3, ο χρήστης Chris Rebert έγραψε: >> On Sat, Sep 15, 2012 at 10:33 AM, Νικόλαος Κούρας wrote: >> > Hello again, >> > >> > one small matter too. >> >> > # get some enviromental values >> > locale.setlocale(locale.LC_ALL, 'el_GR') >> >> > date = datetime.datetime.now().strftime( '%y-%m-%d %H:%M:%S' ) >> > >> > although iam setting greek as locale >> >> Locales don't affect timezones. Otherwise, how would expatriate >> communities, or countries wide enough to span several timezones, >> properly configure their software? >> >> > the time is 8 hours before, like in texas, us >> >> Which is where HostGator operates out of. >> >> > How can i change this to save the correct Greek time in variable $date ? >> >> Use the `pytz` package that Jason pointed out. >> > I did read but wasnt able to set it to greek time. > Please tell me how should i write this. > > date = datetime.datetime.now().strftime( '%y-%m-%d %H:%M:%S',gmt+2 ) > > didnt work out for me. > Does this help? import datetime # The time as UTC (GMT). now_utc = datetime.datetime.utcnow() print(now_utc.strftime('%Y-%m-%d %H:%M:%S')) # The time as UTC+2. now_local = now_utc + datetime.timedelta(hours=2) print(now_local.strftime('%Y-%m-%d %H:%M:%S'))