Friday, 15 May 2015

php - How to return a datetime that can be converted based on different locales? -



php - How to return a datetime that can be converted based on different locales? -

we developing api in php, mysql 1 of fields returns datetime in format of yyyy-mm-dd hh:mm:ss. api in near future can used in different continents. in iso format should save datetime time offset can preserved too?

does time job? or should utilize iso 8601?

i've read in php can homecoming date/time with:

gmdate('y-m-dth:i:sz');

what suggest? in format should homecoming date/time?

when deal dates can come various time zones, should store timestamp in mysql. in case, becomes irrelevant info comes (which continent). true saving data. now, when comes displaying date info people on different continents, have know time zone. using php's datetime, can utilize timestamp database, pair datetimezone , show right time time zone.

also, when need exchange info between various services - providing timestamp allows target application apply range of time zones own formatting purposes. however, date storage should without time zone reliance. that's why timestamp plays huge utility role here - it's utc.

now, let's provide code doesn't become all-talk.

mysql's timestamp data-type stores value integer internally, displays datetime.

$mysql_datetime = '2014-10-15 12:58:55'; // got database $dt = datetime::createfromformat('y-m-d h:i:s', $mysql_datetime); // have object can manipulate dates // let's assume have in new york wants see date formatted according time zone $dt->settimezone(new datetimezone('america/new_york')); echo $dt->format('y.m.d, h:i:s'); // format accepted same `date()` function.

php timezone locale

No comments:

Post a Comment