datetime issue

  • Thread starter Íéêüëáïò Êïýñáò
  • Start date
Í

Íéêüëáïò Êïýñáò

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 the time is 8 hours before, like in texas, us

How can i change this to save the correct Greek time in variable $date ?

Thank you.
 
J

Jason Friedman

# 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 the time is 8 hours before, like in texas, us
How can i change this to save the correct Greek time in variable $date ?

http://docs.python.org/py3k/library/datetime.html#tzinfo-objects
http://stackoverflow.com/questions/117514/how-do-i-use-timezones-with-a-datetime-object-in-python
http://pytz.sourceforge.net/

Reading these links suggests that datetime.now() will return the
system time regardless of your locale setting.
Use a timezone to generate a timestamp for someplace other than where
your server sits.
 
C

Chris Rebert

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.

Cheers,
Chris
 
Í

Íéêüëáïò Êïýñáò

Ôç ÓÜââáôï, 15 Óåðôåìâñßïõ 2012 10:05:49 ì.ì. UTC+3, ï ÷ñÞóôçò Chris Rebert Ýãñáøå:
Locales don't affect timezones. Otherwise, how would expatriate

communities, or countries wide enough to span several timezones,

properly configure their software?






Which is where HostGator operates out of.






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.
 
Í

Íéêüëáïò Êïýñáò

Ôç ÓÜââáôï, 15 Óåðôåìâñßïõ 2012 10:05:49 ì.ì. UTC+3, ï ÷ñÞóôçò Chris Rebert Ýãñáøå:
Locales don't affect timezones. Otherwise, how would expatriate

communities, or countries wide enough to span several timezones,

properly configure their software?






Which is where HostGator operates out of.






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.
 
M

MRAB

Ôç ÓÜââáôï, 15 Óåðôåìâñßïõ 2012 10:05:49 ì.ì. UTC+3, ï ÷ñÞóôçò Chris Rebert Ýãñáøå:
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'))
 
Í

Íéêüëáïò Êïýñáò

Ôç ÓÜââáôï, 15 Óåðôåìâñßïõ 2012 11:28:47 ì.ì. UTC+3, ï ÷ñÞóôçò MRAB Ýãñáøå:
$date ?





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,
 
Í

Íéêüëáïò Êïýñáò

Ôç ÓÜââáôï, 15 Óåðôåìâñßïõ 2012 11:28:47 ì.ì. UTC+3, ï ÷ñÞóôçò MRAB Ýãñáøå:
$date ?





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,
 
D

Dennis Lee Bieber

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
Traceback (most recent call last):

Note the ( ) wrapping the the + clause, with strftime() applied to
the result of that...
 
Í

Íéêüëáïò Êïýñáò

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

still giving me texas,us time for some reason
 
Í

Íéêüëáïò Êïýñáò

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

still giving me texas,us time for some reason
 
Í

Íéêüëáïò Êïýñáò

Ôç ÊõñéáêÞ, 16 Óåðôåìâñßïõ 2012 10:51:18 ð.ì. UTC+3, ï ÷ñÞóôçò Íéêüëáïò Êïýñáò Ýãñáøå:
dn = datetime.datetime.now()

dd = datetime.timedelta(hours=2)

date = dn + dd

date = date.strftime( '%y-%m-%d %H:%M:%S' )



still giving me texas,us time for some reason

which is same as this:

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

this also doesnt work either:

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

if only it would!
 
Í

Íéêüëáïò Êïýñáò

Ôç ÊõñéáêÞ, 16 Óåðôåìâñßïõ 2012 10:51:18 ð.ì. UTC+3, ï ÷ñÞóôçò Íéêüëáïò Êïýñáò Ýãñáøå:
dn = datetime.datetime.now()

dd = datetime.timedelta(hours=2)

date = dn + dd

date = date.strftime( '%y-%m-%d %H:%M:%S' )



still giving me texas,us time for some reason

which is same as this:

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

this also doesnt work either:

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

if only it would!
 
Í

Íéêüëáïò Êïýñáò

Τη ΚυÏιακή, 16 ΣεπτεμβÏίου 2012 8:53:57 Ï€.μ. UTC+3, ο χÏήστης Dennis Lee Bieber έγÏαψε:
On Sat, 15 Sep 2012 22:15:38 -0700 (PDT), Ãéêüëáïò Êïýñáò

<[email protected]> declaimed the following in

gmane.comp.python.general:









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




Traceback (most recent call last):

File "<interactive input>", line 1, in <module>

AttributeError: 'datetime.timedelta' object has no attribute 'strftime'


'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

(e-mail address removed) 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.
 
Í

Íéêüëáïò Êïýñáò

Τη ΚυÏιακή, 16 ΣεπτεμβÏίου 2012 8:53:57 Ï€.μ. UTC+3, ο χÏήστης Dennis Lee Bieber έγÏαψε:
On Sat, 15 Sep 2012 22:15:38 -0700 (PDT), Ãéêüëáïò Êïýñáò

<[email protected]> declaimed the following in

gmane.comp.python.general:









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




Traceback (most recent call last):

File "<interactive input>", line 1, in <module>

AttributeError: 'datetime.timedelta' object has no attribute 'strftime'


'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

(e-mail address removed) 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.
 
S

Steven D'Aprano

]

You seem to be emailing python-list AND posting to comp.lang.python (or
the gmane mirror). Please pick one, or the other, and not both, because
the mailing list and the newsgroup are mirrors of each other. Anything
you send to the mailing list will be mirrored on the newsgroup
automatically, there is no need to manually duplicate the post.


Thank you.
 
Í

Íéêüëáïò Êïýñáò

Ôç ÊõñéáêÞ, 16 Óåðôåìâñßïõ 2012 12:53:42 ì.ì. UTC+3, ï ÷ñÞóôçò Steven D'Aprano Ýãñáøå:
On Sun, 16 Sep 2012 01:25:30 -0700, Íéêüëáïò Êïýñáò wrote:

[...]



You seem to be emailing python-list AND posting to comp.lang.python (or

the gmane mirror). Please pick one, or the other, and not both, because

the mailing list and the newsgroup are mirrors of each other. Anything

you send to the mailing list will be mirrored on the newsgroup

automatically, there is no need to manually duplicate the post.





Thank you.

Iam sorry i didnt do that on purpose and i dont know how this is done.

Iam positng via google groups using chrome, thats all i know.

Whats a mailing list?
Can i get responses to my mail instead of constantly check the google groups site?
 
S

Steven D'Aprano

Τη ΚυÏιακή, 16 ΣεπτεμβÏίου 2012 1:49:38 μ.μ. UTC+3, ο χÏήστης Steven
D'Aprano έγÏαψε:

Thank you, i prefer to be notifies only to thread iam initiating or
answering to not all of te threads. Is this possible?

No. That's not how mailing lists work. Every email gets posted to all
members, unless they go onto "No Mail", in which case they get no emails
at all.

You are not paying anything for the help you are receiving, except to
give your own time in return to help others. We are all volunteers here,
and nobody is going to force you to volunteer in return, but if everyone
only received threads that they initiated, nobody would see new threads
and nobody would get any answers at all.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top