datetime issue
Νικόλαος Κούρας
nikos.gr33k at gmail.com
Sun Sep 16 01:15:38 EDT 2012
Τη Σάββατο, 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 at 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,
More information about the Python-list
mailing list