So I have to use datetime in this project. the more I use it I realized that it can bite, unless used properly.
Let start with a simple example, start with
from datetime import datetime
from the doc, datetime.now() show today date and time.
the time i tested the line is 12:47 on 12 may 2010.
datetime.datetime(2010, 5, 11, 23, 46, 50, 383091)
Notice that the day and the date, is wrong. you should try it to see it yourself. Not wrong but unexpected
datetime.datetime(2010, 5, 12, 4, 56, 13, 315120)
better, but in utc time. That is in 12:56 pm on 12 may 2010
The way to solve it is to implement tzinfo class, which I didn't do, or we can use pytz
Which does it for us anyway. Run the following in the shell
mytz = pytz.timezone('Asia/Kuala_Lumpur')
after setting up the timezone with the right tzinfo. datetime.now() should show the correct datetime.
Note to self, python datetime can bite us,