We are currently porting some php scripts that are pulling datetimes from the facebook API and storing them in a mysql datetime column over to python. However, when we pull the times from the mysql database, the times that were submitted in python are 6 hours later than the times submitted by the php scripts. We are using the same python script to pull and display the values (it’s a django app). So there must be something going on when we are pushing the data into the mysql database.
the updated_time string would be in the following format: “2012-03-15T21:02:50+0000”
php:
$time = $status['updated_time'];
$time = strtotime($time);
$time = date("Y-m-d H:i:s", $time);
python:
timestamp = datetime.strptime(status['updated_time'], "%Y-%m-%dT%H:%M:%S+0000")
I’ve also tried using the python-dateutil module to capture the timezone data and I get the same results.
I’m not sure if django is modifying the value or what. It’s super confusing to me.
I think the reason is timezone, the php
date()function display local time,while python
time.strftime()fill an objectTry this php code (replace
datewithgmdate):and you should have same result