Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #29263 > unrolled thread

datetime issue

Started byΝικόλαος Κούρας <nikos.gr33k@gmail.com>
First post2012-09-15 10:33 -0700
Last post2012-09-15 12:26 -0700
Articles 6 on this page of 66 — 25 participants

Back to article view | Back to comp.lang.python


Contents

  datetime issue Νικόλαος Κούρας <nikos.gr33k@gmail.com> - 2012-09-15 10:33 -0700
    Re: datetime issue Jason Friedman <jason@powerpull.net> - 2012-09-15 12:58 -0600
    Re: datetime issue Chris Rebert <clp2@rebertia.com> - 2012-09-15 12:05 -0700
      Re: datetime issue Νικόλαος Κούρας <nikos.gr33k@gmail.com> - 2012-09-15 12:26 -0700
        Re: datetime issue MRAB <python@mrabarnett.plus.com> - 2012-09-15 21:28 +0100
          Re: datetime issue Νικόλαος Κούρας <nikos.gr33k@gmail.com> - 2012-09-15 22:15 -0700
            Re: datetime issue Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2012-09-16 01:53 -0400
              Re: datetime issue Νικόλαος Κούρας <nikos.gr33k@gmail.com> - 2012-09-16 00:51 -0700
                Re: datetime issue Νικόλαος Κούρας <nikos.gr33k@gmail.com> - 2012-09-16 01:18 -0700
                Re: datetime issue Νικόλαος Κούρας <nikos.gr33k@gmail.com> - 2012-09-16 01:18 -0700
              Re: datetime issue Νικόλαος Κούρας <nikos.gr33k@gmail.com> - 2012-09-16 00:51 -0700
              Re: datetime issue Νικόλαος Κούρας <nikos.gr33k@gmail.com> - 2012-09-16 01:25 -0700
                Re: datetime issue Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-09-16 09:53 +0000
                  Re: datetime issue Νικόλαος Κούρας <nikos.gr33k@gmail.com> - 2012-09-16 03:15 -0700
                    Re: datetime issue Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-09-16 10:49 +0000
                      Re: datetime issue Νικόλαος Κούρας <nikos.gr33k@gmail.com> - 2012-09-16 03:54 -0700
                        Re: datetime issue Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-09-16 11:34 +0000
                          Re: datetime issue Νικόλαος Κούρας <nikos.gr33k@gmail.com> - 2012-09-16 04:56 -0700
                            Re: datetime issue Dave Angel <d@davea.name> - 2012-09-16 15:31 -0400
                    Obnoxious postings from Google Groups (was: datetime issue) Ben Finney <ben+python@benfinney.id.au> - 2012-09-16 23:18 +1000
                      Re: Obnoxious postings from Google Groups (was: datetime issue) pandora.koura@gmail.com - 2012-09-16 08:41 -0700
                        Re: Obnoxious postings from Google Groups (was: datetime issue) Joel Goldstick <joel.goldstick@gmail.com> - 2012-09-16 11:57 -0400
                          Re: Obnoxious postings from Google Groups (was: datetime issue) pandora.koura@gmail.com - 2012-09-16 09:06 -0700
                            Re: Obnoxious postings from Google Groups (was: datetime issue) Joel Goldstick <joel.goldstick@gmail.com> - 2012-09-16 12:23 -0400
                            Re: Obnoxious postings from Google Groups (was: datetime issue) Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-09-16 16:54 +0000
                            Re: Obnoxious postings from Google Groups Mark Lawrence <breamoreboy@yahoo.co.uk> - 2012-09-16 20:26 +0100
                            Re: Obnoxious postings from Google Groups (was: datetime issue) Gene Heskett <gheskett@wdtv.com> - 2012-09-16 12:32 -0400
                          Re: Obnoxious postings from Google Groups (was: datetime issue) pandora.koura@gmail.com - 2012-09-16 09:06 -0700
                        Re: Obnoxious postings from Google Groups Terry Reedy <tjreedy@udel.edu> - 2012-09-16 12:30 -0400
                        Re: Obnoxious postings from Google Groups (was: datetime issue) Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-09-16 16:52 +0000
                        Re: Obnoxious postings from Google Groups Mayuresh Kathe <mayuresh@kathe.in> - 2012-09-17 01:09 +0530
                        Re: Obnoxious postings from Google Groups (was: datetime issue) Jamie Paul Griffin <jamie@kode5.net> - 2012-09-17 14:28 +0100
                      Re: Obnoxious postings from Google Groups (was: datetime issue) pandora.koura@gmail.com - 2012-09-16 08:44 -0700
                        Re: Obnoxious postings from Google Groups (was: datetime issue) Chris Angelico <rosuav@gmail.com> - 2012-09-17 01:57 +1000
                          Re: Obnoxious postings from Google Groups (was: datetime issue) pandora.koura@gmail.com - 2012-09-16 09:02 -0700
                          Re: Obnoxious postings from Google Groups (was: datetime issue) pandora.koura@gmail.com - 2012-09-16 09:02 -0700
                        Re: Obnoxious postings from Google Groups (was: datetime issue) Gene Heskett <gheskett@wdtv.com> - 2012-09-16 12:28 -0400
                      Re: Obnoxious postings from Google Groups (was: datetime issue) alex23 <wuwei23@gmail.com> - 2012-09-16 17:47 -0700
                        Re: Obnoxious postings from Google Groups (was: datetime issue) Roy Smith <roy@panix.com> - 2012-09-16 20:55 -0400
                          Re: Obnoxious postings from Google Groups (was: datetime issue) alex23 <wuwei23@gmail.com> - 2012-09-16 18:14 -0700
                      Re: Obnoxious postings from Google Groups Robert Miles <robertmiles@teranews.com> - 2012-09-21 00:22 -0500
                      Re: Obnoxious postings from Google Groups (was: datetime issue) Grant Edwards <invalid@invalid.invalid> - 2012-09-21 15:07 +0000
                        Re: Obnoxious postings from Google Groups (was: datetime issue) Walter Hurry <walterhurry@lavabit.com> - 2012-09-21 22:11 +0000
                        Re: Obnoxious postings from Google Groups (was: datetime issue) Hank Gay <hank.gay+eternal.september@gmail.com> - 2012-09-21 20:51 -0400
                          Re: Obnoxious postings from Google Groups (was: datetime issue) Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2012-09-22 00:13 -0400
                          Re: Obnoxious postings from Google Groups (was: datetime issue) Grant Edwards <invalid@invalid.invalid> - 2012-09-23 22:25 +0000
                    Re: datetime issue Roy Smith <roy@panix.com> - 2012-09-16 09:22 -0400
                      Re: datetime issue Chris Angelico <rosuav@gmail.com> - 2012-09-16 23:32 +1000
                        Re: datetime issue Chris Angelico <rosuav@gmail.com> - 2012-09-17 00:10 +1000
                        gc.get_objects() Matteo Boscolo <matteo.boscolo@boscolini.eu> - 2012-09-17 14:42 +0200
                          Re: gc.get_objects() Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-09-17 14:16 +0000
                            Re: gc.get_objects() Chris Angelico <rosuav@gmail.com> - 2012-09-18 02:09 +1000
                            Re: gc.get_objects() Matteo Boscolo <matteo.boscolo@boscolini.eu> - 2012-09-17 19:23 +0200
                            Re: gc.get_objects() Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2012-09-17 17:43 +0000
                Re: datetime issue "Günther Dietrich" <gd.usenet@spamfence.net> - 2012-09-16 15:22 +0200
                  Re: datetime issue pandora.koura@gmail.com - 2012-09-16 08:43 -0700
                    Re: datetime issue Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2012-09-16 15:35 -0400
                Re: datetime issue MRAB <python@mrabarnett.plus.com> - 2012-09-16 16:27 +0100
                  Re: datetime issue pandora.koura@gmail.com - 2012-09-16 08:40 -0700
                    Re: datetime issue Chris Angelico <rosuav@gmail.com> - 2012-09-17 01:54 +1000
                    Re: datetime issue Mark Lawrence <breamoreboy@yahoo.co.uk> - 2012-09-16 20:23 +0100
                  Re: datetime issue pandora.koura@gmail.com - 2012-09-16 08:40 -0700
                Re: datetime issue Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2012-09-16 15:37 -0400
              Re: datetime issue Νικόλαος Κούρας <nikos.gr33k@gmail.com> - 2012-09-16 01:25 -0700
          Re: datetime issue Νικόλαος Κούρας <nikos.gr33k@gmail.com> - 2012-09-15 22:15 -0700
      Re: datetime issue Νικόλαος Κούρας <nikos.gr33k@gmail.com> - 2012-09-15 12:26 -0700

Page 4 of 4 — ← Prev page 1 2 3 [4]


#29343

FromMark Lawrence <breamoreboy@yahoo.co.uk>
Date2012-09-16 20:23 +0100
Message-ID<mailman.810.1347823432.27098.python-list@python.org>
In reply to#29317
On 16/09/2012 16:54, Chris Angelico wrote:
> On Mon, Sep 17, 2012 at 1:40 AM,  <pandora.koura@gmail.com> wrote:
>> Cant it be written more easily as:
>>   date = (datetime.datetime.utcnow(+2)
>>
>> i know this is not thhe correct syntax but it just needs a way to add GMT+2 hours since utc=gmt
>
> I've dithered about whether to open this can of worms or let sleeping
> dogs lie, and I finally decided to make some metaphor potpourri.
>
> Simple UTC offsets are not the same thing as local time. There are a
> variety of other considerations, but the main one is Daylight Robbery
> Time, where every government wants to put its own stamp on things by
> fiddling with the DST rules a bit. Most places will move their clocks
> an hour forward for summer and then back for winter. But!
>
> * Some places are sensible and don't have DST at all (eg
> Australia/Queensland, America/Arizona)
> * Northern hemisphere summer corresponds to southern hemisphere
> winter, and vice versa
> * Everyone has a different way of defining the boundaries of summer and winter
> * And just to confuse us all, Irish Standard Time is used in summer,
> and they *subtract* an hour for winter time!
>
> The only way to handle timezones correctly and keep yourself even
> marginally sane is to hand the job on to somebody else. I dodged the
> whole issue by letting our Postgres database handle everything for us
> (date/time formats, timezones, the lot), and having our internal
> systems all just work in UTC. You'll likely find it easiest to do the
> same thing with a Python library.
>
> Just don't try to pretend to yourself that Greece uses GMT+2, because
> it's not that simple. For one thing, it's currently summer there...
>
> ChrisA
>

I guess that Double British Summer Time made things twice as difficult?

-- 
Cheers.

Mark Lawrence.

[toc] | [prev] | [next] | [standalone]


#29318

Frompandora.koura@gmail.com
Date2012-09-16 08:40 -0700
Message-ID<mailman.795.1347810046.27098.python-list@python.org>
In reply to#29315
Τη Κυριακή, 16 Σεπτεμβρίου 2012 6:30:15 μ.μ. UTC+3, ο χρήστης MRAB έγραψε:
> 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.

Cant it be written more easily as:
 date = (datetime.datetime.utcnow(+2)

i know this is not thhe correct syntax but it just needs a way to add GMT+2 hours since utc=gmt

[toc] | [prev] | [next] | [standalone]


#29348

FromDennis Lee Bieber <wlfraed@ix.netcom.com>
Date2012-09-16 15:37 -0400
Message-ID<mailman.814.1347824402.27098.python-list@python.org>
In reply to#29295
On Sun, 16 Sep 2012 16:27:16 +0100, MRAB <python@mrabarnett.plus.com>
declaimed the following in gmane.comp.python.general:


> The line should be this:
> 
> date = (datetime.datetime.utcnow() + datetime.timedelta(hours=8) 
> ).strftime('%Y-%m-%d %H:%M:%S')
>
	I think "hours = 2"... UTC to Athens is two hours... the OP was
trying 8 hours to get from US Central to Greece (and not accounting for
possible daylight savings times)
-- 
	Wulfraed                 Dennis Lee Bieber         AF6VN
        wlfraed@ix.netcom.com    HTTP://wlfraed.home.netcom.com/

[toc] | [prev] | [next] | [standalone]


#29296

FromΝικόλαος Κούρας <nikos.gr33k@gmail.com>
Date2012-09-16 01:25 -0700
Message-ID<mailman.787.1347783937.27098.python-list@python.org>
In reply to#29282
Τη Κυριακή, 16 Σεπτεμβρίου 2012 8:53:57 π.μ. UTC+3, ο χρήστης Dennis Lee Bieber έγραψε:
> On Sat, 15 Sep 2012 22:15:38 -0700 (PDT), Íéêüëáïò Êïýñáò
> 
> <nikos.gr33k@gmail.com> declaimed the following in
> 
> gmane.comp.python.general:
> 
> 
> 
> 
> 
> > 
> 
> > If i wanted to alter the following line, how would i write it?
> 
> > 
> 
> > date = datetime.datetime.now()+datetime.timedelta(hours=2).strftime( '%y-%m-%d %H:%M:%S')
> 
> > 
> 
> > But that doesnt work,
> 
> 
> 
> 	What did you expect? Object methods bind tighter than operators so
> 
> what you have is the equivalent of
> 
> 
> 
> dn = datetime.datetime.now()
> 
> dd = datetime.timedelta(hours=2).strftime(...)
> 
> date = dn + dd
> 
> 
> 
> 	Try
> 
> 
> 
> >>> import datetime
> 
> >>> date = datetime.datetime.now()+datetime.timedelta(hours=2).strftime( '%y-%m-%d %H:%M:%S')
> 
> Traceback (most recent call last):
> 
>   File "<interactive input>", line 1, in <module>
> 
> AttributeError: 'datetime.timedelta' object has no attribute 'strftime'
> 
> >>> date = (datetime.datetime.now()+datetime.timedelta(hours=2) ).strftime( '%y-%m-%d %H:%M:%S')
> 
> >>> date
> 
> '12-09-16 03:50:44'
> 
> >>> 
> 
> 
> 
> 	Note the ( ) wrapping the the + clause, with strftime() applied to
> 
> the result of that...
> 
> -- 
> 
> 	Wulfraed                 Dennis Lee Bieber         AF6VN
> 
>         wlfraed@ix.netcom.com    HTTP://wlfraed.home.netcom.com/



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.

[toc] | [prev] | [next] | [standalone]


#29281

FromΝικόλαος Κούρας <nikos.gr33k@gmail.com>
Date2012-09-15 22:15 -0700
Message-ID<mailman.780.1347773064.27098.python-list@python.org>
In reply to#29275
Τη Σάββατο, 15 Σεπτεμβρίου 2012 11:28:47 μ.μ. UTC+3, ο χρήστης MRAB έγραψε:
> 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, οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½ οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½ <nikos.gr33k@gmail.com> wrote:
> 
> >> > Hello again,
> 
> >> >
> 
> >> > one small matter too.
> 
> >>
> 
> >> > # get some enviromental values
> 
> >> > locale.setlocale(locale.LC_ALL, 'el_GR')
> 
> >> <snip>
> 
> >> > 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'))

If i wanted to alter the following line, how would i write it?

date = datetime.datetime.now()+datetime.timedelta(hours=2).strftime( '%y-%m-%d %H:%M:%S')

But that doesnt work,

[toc] | [prev] | [next] | [standalone]


#29274

FromΝικόλαος Κούρας <nikos.gr33k@gmail.com>
Date2012-09-15 12:26 -0700
Message-ID<mailman.775.1347737215.27098.python-list@python.org>
In reply to#29272
Τη Σάββατο, 15 Σεπτεμβρίου 2012 10:05:49 μ.μ. UTC+3, ο χρήστης Chris Rebert έγραψε:
> On Sat, Sep 15, 2012 at 10:33 AM, Νικόλαος Κούρας <nikos.gr33k@gmail.com> wrote:
> 
> > Hello again,
> 
> >
> 
> > one small matter too.
> 
> 
> 
> > # get some enviromental values
> 
> > locale.setlocale(locale.LC_ALL, 'el_GR')
> 
> <snip>
> 
> > 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.
> 
> 
> 
> Cheers,
> 
> Chris

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.

[toc] | [prev] | [standalone]


Page 4 of 4 — ← Prev page 1 2 3 [4]

Back to top | Article view | comp.lang.python


csiph-web