PHP - Time Zone Conversion After Fetching Remote File
Purpose: To get time zone of a remote file in my time zone. I have to download a file daily (mp3, don't worry its legal!) from BBC. Problem is that sometimes BBC doesn't update the file and i have to download entire file to check if it has been updated or not. Hence i decided to code a page that gives me date and time of that remote file. I have successfully compiled the code (that i got from internet). But the time returns in EST. I want the time in IST (indian std time Asia/Calcutta). CURLINFO_FILETIME has bee used. Below is code.
Pls suggest me how to convert EST to IST - Warning: I am a newbie. But i can follow instructions Code: [Select] <?php $curl = curl_init('http://wsdownload.bbc.co.uk/hindi/tx/32mp3/din_bhar.mp3'); //don't fetch the actual page, you only want headers curl_setopt($curl, CURLOPT_NOBODY, true); //stop it from outputting stuff to stdout curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); // attempt to retrieve the modification date curl_setopt($curl, CURLOPT_FILETIME, true); $result = curl_exec($curl); if ($result === false) { die (curl_error($curl)); } $timestamp = curl_getinfo($curl, CURLINFO_FILETIME); if ($timestamp != -1) { //otherwise unknown echo "BBC Hindi was last modified" . date("d-m-Y h:i:s A T", $timestamp); //etc } ?> I have used it with custom getRemoteFileSize function he - Code: [Select] http://island.web44.net/bbc.php Similar TutorialsHello, I tried to implement some PHP code to enable a web page to show "Dinner" specials versus "Lunch" specials based on the time. The business is located in the Eastern Time Zone, so I only need to routine to work based on Eastern Time (New York). What I am noticing is that the server is processing the lines of code so fast that the command to establish the correct time for the remaining code is not always being acknowledged. This line of code appears to be processing too fast for the remaining lines of code: date_default_timezone_set ( "America/New_York" ); Is there some additional code I can put in place to make sure the correct time is always ascertained? I need the $hourmin variable to always return a combination of hour + minute based on 24-hour time and Eastern Time zone. My code is as follows: <?php $name8 = file_get_contents("test/special8name.txt"); date_default_timezone_set ( "America/New_York" ); $gethour = date("H"); $getminutes = $gettimedate["minutes"]; $gettimedate = date(); $hourmin = $gethour . $getminutes; $currentday = date("l", time()); $currentdate = date("M j, Y"); if ($hourmin < 1500 && $currentday <> "Saturday" && $currentday <> "Sunday") { echo "<span class=\"namesred\">$name8 </span>"; } else if ( $hourmin > 1500 && $hourmin < 2300 && $currentday <> "Saturday" && $currentday <> "Sunday") { echo "<span class=\"namesblue\">$name8 </span>"; } else if ( $currentday == "Saturday" or $currentday == "Sunday") { echo "<span class=\"namesblue\">$name8 </span>"; } ?> Hello Everyone, I am on windows server and In my ini file server time zone declared as below
[server_settings] but my application installed on another timezone eg: 'America/Los_Angeles' time zone. using date_default_timezone_get() i am always getting Europe/London timezone as it's declared in ini file. How to get local timezone(wherever application is installed) here? Thanks Krish How to set the time zone? All 3 shows the same time??? <?php date_default_timezone_set("Australia/Melbourne"); echo "time=" . time(); ?> <?php echo "time=" . time(); ?> <?php date_default_timezone_set("Antarctica/Palmer"); echo "time=" . time(); ?> Having a problem since the time change of 1 hour. Times now show 2:08 when it is 3:08 I am using: Code: [Select] date_default_timezone_set('EST'); date('g:i a'); Any way to fix this to show corrent time? Hi My code was working perfectly when my hosting company located in Japan. But i transfer to US(hostgator) and now my time zone changes asia/tokyo to America/Chicago. Therefore, all my codes, scripts and sites are following one day behind of Japan local time. Great appreciate for any help. My code is below: <?php $host = "localhost"; $user = "user"; $pass = "pass"; $data = "mysql_db"; $cn = mysql_connect($host, $user, $pass) or trigger_error(mysql_error(),E_USER_ERROR); mysql_select_db($data, $cn) or die("Could not Connect Database Please Try again later !!!"); mysql_query("set names utf-8", $cn); if(date("H:i:s") < '03:00:00') // Changes midnight 00:00:00 to 03:00:00 $midnight = 1; else $midnight = 0; $TODAY__ = mktime(0, 0, 0, date("n"), date("d") - $midnight, date("Y")); date_default_timezone_set('Asia/Tokyo'); ?> Are time zones when calling the date function automatically decided based on where you live? Or is that something that I have to implement--Because the time is wrong according to my time zone. I am trying to get local date/time. In my php file I am setting my timezone using $timezone = "America/Toronto"; putenv ('TZ=' . $timezone); Then I use the following to get current date and time print_r (getdate()); but my date displays in GMT, What am I doing wrong? As in the code above I am in Toronto and I need EST. By using the function date_default_timezone_set() I am trying to set my timezone. Do I have to change anything else in any other files like php.ini? I am sorry I have absolutely no idea where this question fits in this forum bcoz its related to PHP , MySQL and Javascript... So here is my question .. I use MySql database to store posts.. where 'postdate and time' is saved using 'CURRENT_TIMESTAMP' of MySql that offcourse gives "2010-08-31 09:47:10" format... When I have to calculate when the post was posted just before loading the posts on users wall e.g. "2 min ago"... I take the 'postdate and time' from database then use strtotime() function in php to convert it to string you know since jan 1 1970. Now this time stamp is sent to javascript function which uses 'Date' Object to create current time and then 'getTime' to get the string like one Mentioned earlier. it then calculates the difference and displays it.. Just to inform you.. I used javascript to I may refresh "posted since" periodically using "SetInterval()" But the problem here arises. There is difference of 1 Hour and 24 Sec in both times....... Sorry If I confused you... But the problem is simple. In javascript date object and MySql --> strtotime() there is time difference... How I can correct it ??? please Help ... Codes: 1. function to convert str to time function change($date){ $time_early=strtotime($date); return $time_early; } 2. javascript Code to check "Post Since" function calc_difference() { $("[name=posttime]").each(function() { var current=$(this).attr("id"); localtimevalue = new Date(); d = localtimevalue.getTime(); var d= parseInt(d)/1000; var diff=d-parseInt(current); var diff=parseInt(diff); var min=parseInt(diff/60); var hours=parseInt(diff/3600); var days=parseInt(diff/86400); var months=parseInt(diff/2592000); var years=parseInt(diff/31104000); if( min==0 ){ $(this).text("Posted: "+diff +" seconds ago "); } if(min>0 && hours==0 && days==0 && months==0){ if(min==1){ $(this).text("Posted: a minute ago "); }else{ $(this).text("Posted: "+min +" minutes ago "); } } if(min>0 && hours>0 && days==0 && months==0){ if(hours==1){ $(this).text("Posted: an hour ago "); }else{ $(this).text("Posted: "+hours +" hours ago "); } } if(days>0 && months==0 && years==0){ if(days==1){ $(this).text("Posted: a day ago "); }else{ $(this).text("Posted: "+days +" days ago "); } } if(months>0 && years==0 ){ if(months==1){ $(this).text("Posted: a month ago "); }else{ $(this).text("Posted: "+months +" months ago "); } } if(years>0){ if(years==1){ $(this).text("Posted: a year ago "); }else{ $(this).text("Posted: "+years +" years ago "); } } }); } Javascript function is called on load and Jquery's .each function is used to update all post's time. I have all the dates stored in my database as UTC and I want to retrieves these UTC date/time to show the local time zone. So, example, If I live in New York, I want it to show east coast time zone and not the Universal Time. Any idea? Hi,
I am working on coupon script which generate coupon.
The coupon script have two types, one is redemption and second one is printable in the same process it send sms to customer.
But issue is when it send SMS, sometime SMS works nice and lots of time SMS content got missing.
I could not understand why it happening. Is it scripting issue or another?
The script code as below:
----------------------------------------------------------------------------------------------------------
//Send coupon code to customer by SMS
$smsparameters = "select * from cs_options where option_id in ('23','24','25','26')";
if(!($smsparametersresult = mysql_query($smsparameters))) { echo $smsparameters.mysql_error(); exit; }
while($smsparametersrow = mysql_fetch_array($smsparametersresult)) {
$smsparametersarray[] = $smsparametersrow['option_value'];
}
define('SMS_SERVICE_URL', $smsparametersarray[0]);
define('KEY', $smsparametersarray[1]);
define('USERNAME', $smsparametersarray[2]);
define('PASSWORD', $smsparametersarray[3]);
$automationquery = "select * from cs_automation where automation_id='6'";
if(!($automationresult = mysql_query($automationquery))) { echo $automationquery.mysql_error(); exit; }
$automationrow = mysql_fetch_array($automationresult);
$automationrow['automation_value'];
if($automationrow['automation_value']=='1') {
$sms_order_id = $_SESSION['new_order_id'];
$current_date = date('Y-m-d');
$smsquery = "select * from cs_order as ord left join cs_customer as cust on ord.order_user_id = cust.customer_id where ord.order_id = '$sms_order_id'";
if(!($smsresult = mysql_query($smsquery))) { echo $smsquery.mysql_error(); exit; }
$sms_items = mysql_fetch_assoc($smsresult);
$order_coupon_id4 = explode(", ", $customer_email_items['order_coupon_id']);
foreach($order_coupon_id4 as $coup_id) {
$coupon_id = $coup_id['order_coupon_id'];
$query = "select * from cs_coupons as coup inner join cs_company as comp on coup.coupons_store = comp.retailer_id inner join cs_payments_currency as curr on coup.coupons_currency_id = curr.currency_id inner join cs_countries as cont on comp.country = cont.country_id inner join cs_states as stat on comp.state = stat.state_id inner join cs_cities as citi on comp.city = citi.city_id inner join cs_area as aria on comp.local_area = aria.area_id where coup.coupons_id = '$coupon_id'";
if(!($result = mysql_query($query))) { echo $query.mysql_error(); exit; }
$coupon = mysql_fetch_array($result);
$coup_name = $coupon['coupons_name'];
$coup_code = $coupon['coupons_code'];
$custdiscount = $coupon['coupons_product_discount'];
$coup_valid_date = date("d-m-Y", strtotime($coupon['coupons_exp_date']));
$couponcodeforsms = $sms_items['order_coupon_code'];
$couponcodeforsms1 = explode(", ", $sms_items['order_coupon_code']);
$smscount = count($couponcodeforsms1);
$mobilenoforsms = $sms_items['customer_mobile'];
$custnameforsms = ucwords($sms_items['customer_fname']);
$company_name = $coupon['company_name'];
$company_address = $coupon['city_name'];
$ch=curl_init();
curl_setopt($ch, CURLOPT_URL, "".SMS_SERVICE_URL."?user=".USERNAME."&password=".PASSWORD."&phone=".urlencode($mobilenoforsms)."&text=".urlencode('Hi '.$custnameforsms.', Coupon from CrackMyDeal : '.$coup_code.', '.$custdiscount.'% off on '.$coup_name.' at '.$company_name.', '.$company_address.', Valid till '.$coup_valid_date.'. T&C Apply.')."&type=t&senderid=".KEY."");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
curl_close($ch);
}
}
----------------------------------------------------------------------------------------------------------------
The SMS which works nice:
Hi Paresh, Coupon from CrackMyDeal : CRACKD2014, 20% off on WebHosting (Business) at Unique InfoTech, Kamothe, Valid till 31-12-2014. T&C Apply.
--------------------------------------------------------------------------------------------------------------
And missing content SMS :
Hi Paresh, Coupon from CrackMyDeal : , % off on at , , Valid till 01-01-1970. T&C Apply.
-------------------------------------------------------------------------------------------------------------- I need to compare current time to data based time. Time in the database is in this format > 00:00:00 Easy enough. >>>>What I need is to convert "00:00:00" format into "time();" format<<<< The opposite is below...it's all I could come up with so far. <? $gettime = time(); $displayTime = date('H:i:s', time()); echo $displayTime; ?> Thank you. I am writing an app that takes ofx banking files files on convert them to csv for excel or importation into sql. I am on the last task. Converting the nonstandard date:time stamp. I am using preg_replace(). I am not the best at regular expressions. I am getting this error: "Warning: preg_replace() [function.preg-replace]: Unknown modifier '\' in C:\xampp\htdocs\banking\ofx-date.php on line 13" CODE: // Date Time 20110228000600 (2011/02/28/, 00:06:00) // Expected Return '<DTPOSTED>2011/02/28,00:06:00' $ofxDate = '<DTPOSTED>20110228000600'; $ofxNewDate = substr($ofxDate,0,10) . substr($ofxDate,10,4) . '/' . substr($ofxDate,14,2) . '/' . substr($ofxDate,16,2) . ',' . substr($ofxDate,18,2) . ':' . substr($ofxDate,20,2) . ':' . substr($ofxDate,22,2); echo htmlentities($ofxNewDate) . PHP_EOL;; $patternA = '/<DTPOSTED>/\b[0-9]+\b'; //$replacement = '/<DTPOSTED>/'; $stringB = preg_replace($patternA, $ofxNewDate, ofxDate); echo htmlentities($StringB) . PHP_EOL; Hi - I have been searching for a way to select the stored time from a database (stored in 24h format - 13:20:00) and display it as 12h format. I have checked a number of forums and nothing quite seems to fit the bill. I would like it to display as 2:00pm, 12:00am, etc. Here is what I have so far: $sql = ('SELECT * FROM events WHERE active="1" AND event_date >= CURRENT_DATE AND MONTH(event_date) = 1 order by event_date ASC, event_start ASC'); $result = mysql_query($sql); $num_rows = mysql_num_rows($result); // Yes Item if (!($num_rows == 0)) { $myrow = mysql_fetch_array($result); echo ('<span class="bold" style="font-size:14px">January</span>'); do { printf ('<span>Event Time: %s', $myrow['event_start']); if ($myrow['event_end'] != '') { printf (' to %s', $myrow['event_end']); } } while ($myrow = mysql_fetch_array($result)); } Right now this just shows the regular 24h format (hh:mm:ss) for any events in the month of January. I would like both "event_start" and "event_end" to show up in 12h format. I have tried a number of things but none of it works. I'm SURE it is something simple that I have missed. Thanks in advance for any help. Hi, I am trying to fetch a file with function file_get_contents() from a website, but am getting following error. [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.0 403 Forbidden in /data/22/1/27/17/1842180/user/1999295/htdocs/web/modules/index.php on line 14. using following code, Code: [Select] $content = file_get_contents($source); $handle = fopen($destination, 'wb'); fwrite($handle, $content); fclose($handle); does it have something to with http header, which might be required to set as HTTP/1.1 in php Regards, Abhishek Dear PHPFreak members, I have been searching a solution for serving a file download via my website. The file to be downloaded is actually on a remote server. What i need is a code that serves as a download medium without actually downloading the file to my web server. Something like masking file url Can anyone help me with it ??? Have been trying this since days. But no solution till date. Hi all, I am in need of php code for word file conversion. That is to convert word .docx file to .doc file Someone please provide me with a solution. Thanks. This topic has been moved to Other Web Server Software. http://www.phpfreaks.com/forums/index.php?topic=351153.0 I need to check a file's size with php and ssh. Everything I've seen online for remote files uses curl and port 80. I'll be checking a LAN computer that isn't running a webserver, but is running an SSH server. How can I do this? I've tried this: Code: [Select] <?php $tomorrow = date ('n-j-y'); echo system(ssh root@192.168.2.169 ls -lah "/MacRadio X/WMIS Logs/WMIS $tomorrow Log" | awk {print $5}); ?> but it didn't work. I got a T_VARIAABLE error. This was the same command I used right from the command line, and it worked. I'll also need to add a check to the file size, and if it's less than 175K, send me an email...but I'll work on that after I have the first part working. Thanks! Hello I am in need of writting to a txt file on a remote server. When trying I get this error: "failed to open stream: HTTP wrapper does not support writeable connections in /home....." How can I write to a siply txt file on a remote server? |