Small, short code snippets that other people may find useful. Do you have a good regex that you would like to share? Share it! Even better, the code can be commented on, and improved.
This function requires a parameter, which is the offset (in hours) from the server time. It will generate the time according to their settings (that they have specified, perhaps in a db?).
<?php
echo returnUserTime(-3);
// user is 3 hours behind the server time
// returns the time from 3 hours ago
echo returnUserTime(3);
// doesn't need a + sign,
// returns users time 3 hours ahead of the server time
?>
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Alternatively, if you have a date stored in a database that you'd like to convert to a users time that they have set, you can pass a timestamp parameter
function returnUserTime($offset,$timestamp){
if($offset != 0){
return date("F jS, Y \a\\t g:i A",$timestamp+($offset*60*60));
} ELSE {
return date("F jS, Y \a\\t g:i A",$timestamp);
}
}
echo returnUserTime(-2,$time_stamp_from_db);
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.