Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!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.070 X-Spam-Evidence: '*H*': 0.86; '*S*': 0.00; 'used.': 0.07; 'from:addr:mrabarnett.plus.com': 0.16; 'from:addr:python': 0.16; 'from:name:mrab': 0.16; 'message-id:@mrabarnett.plus.com': 0.16; 'received:84.93': 0.16; 'received:84.93.230': 0.16; 'sits': 0.16; 'subject:issue': 0.16; 'utc': 0.16; 'wrote:': 0.17; 'this:': 0.23; "i've": 0.23; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'skip:( 20': 0.28; 'received:192.168.1.3': 0.29; 'received:84': 0.32; 'programming,': 0.33; 'to:addr:python-list': 0.33; 'skip:d 20': 0.34; 'server': 0.35; 'but': 0.36; "didn't": 0.36; 'should': 0.36; 'subject:: ': 0.38; 'gives': 0.39; 'instead': 0.39; 'to:addr:python.org': 0.39; 'received:192': 0.39; 'where': 0.40; 'received:192.168': 0.40; 'time,': 0.62; 'between': 0.63; 'hours': 0.66; 'reply': 0.66; 'header:Reply-To:1': 0.68; '8bit%:100': 0.70; 'reply-to:no real name:2**0': 0.72; 'attention': 0.75; 'reply-to:addr:python.org': 0.84 X-CM-Score: 0.00 X-CNFS-Analysis: v=2.0 cv=IekFqBWa c=1 sm=1 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=AAvI7MrX_rgA:10 a=ihvODaAuJD4A:10 a=OUOv7kDek9cA:10 a=IkcTkHD0fZMA:10 a=EBOSESyhAAAA:8 a=8AHkEIZyAAAA:8 a=MDrHMdyo4tAA:10 a=mI26WLHDzFomBKCSaqAA:9 a=QEXdDO2ut3YA:10 a=0nF1XD0wxitMEM03M9B4ZQ==:117 X-AUTH: mrabarnett:2500 Date: Sun, 16 Sep 2012 16:27:16 +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> <8370412f-5176-45ff-87eb-72cbca5149d5@googlegroups.com> In-Reply-To: Content-Type: text/plain; charset=UTF-8; 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: 29 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1347809414 news.xs4all.nl 6896 [2001:888:2000:d::a6]:53747 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:29315 On 2012-09-16 09:25, Νικόλαος Κούρας wrote: [snip] > > date = ( datetime.datetime.now() + datetime.timedelta(hours=8) ).strftime( '%y-%m-%d %H:%M:%S') > > but iam giving +8 hours which is the time difference between texas, us where the server sits and Greece's time. > > cant we somehow tell it to use GMT+2 ? > > also it would be nice if datetime.datetime.now(GMT+2) can be used. > In programming, you need attention to details. My reply didn't use datetime.datetime.now(), it used datetime.datetime.utcnow(). datetime.datetime.now() gives the local time (local to the system on which it is running). datetime.datetime.utcnow() gives the UTC (GMT) time, which is the same everywhere. The line should be this: date = (datetime.datetime.utcnow() + datetime.timedelta(hours=8) ).strftime('%Y-%m-%d %H:%M:%S') I've also used '%Y' instead of '%y' because I prefer 4 digits for the year.