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.gr...@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'))

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to