Tag Archives: time
Example of Simple Retry Technique to Deal with Timeouts in Android
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.net.URI; import org.apache.http.HttpResponse; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.DefaultHttpClient; public class TestHttpGet { public String executeHttpGetWithRetry() throws Exception { int retry = 3; int count = 0; while (count < retry) { count … Continue reading
Create a countdown timer that counts back in Javascript
Div to show the countdown timer. <div id="showRemain"></div> Javascript code: <script type="text/javascript"> function countDown(){ var timeA = new Date(); var timeB = new Date("10/31/2000 03:04:05"); var timeDifference = timeB-timeA; if(timeDifference>=0){ timeDifference=timeDifference/1000; timeDifference=Math.floor(timeDifference); var wan=Math.floor(timeDifference/86400); var l_wan=timeDifference%86400; var hour=Math.floor(l_wan/3600); var l_hour=l_wan%3600; … Continue reading
Removing event listeners in Actionscript
var timer:Timer = new Timer(1000); timer.addEventListener(TimerEvent.TIMER, onTimer); timer.start(); function onTimer(evt:TimerEvent):void { watch.hand.rotation +=5; if (watch.hand.rotation >= 25) { timer.removeEventListener(TimerEvent. TIMER, onTimer); } }
Actionscript timer event
var timer:Timer = new Timer(1000); timer.addEventListener(TimerEvent.TIMER, onTimer); timer.start(); function onTimer(evt:TimerEvent):void { watch.hand.rotation +=5; }
Using timers in c#
A simple program illustrating the usage of timers in c# using System; using System.Timers; class TestTimer { public static void Main () { Timer timer = new Timer(); timer.Elapsed + = new ElapsedEventHandler(DisplayTimeEvent); timer.Interval = 1000; timer.Start(); timer.Enabled = … Continue reading
Find difference in dates in mysql
We can use the TIMEDIFF and TIME_TO_SEC functions to find the time difference in seconds. SELECT TIME_TO_SEC(TIMEDIFF(’2010-01-09 10:24:46′,’2010-01-09 10:23:46′));
Timing program execution in PHP using PEAR
We can use the PEAR Benchmark module to profile a program, to see how long each statement takes to execute. <?php require_once ‘Benchmark/Timer.php’; $timer =& new Benchmark_Timer(true); $timer->start(); // some program code here $timer->setMarker(’one’); // some more program … Continue reading
Determine how much time a function takes to execute in PHP
To determine how much time a single function takes to execute, we can compare time in milliseconds before running the function against the time in milliseconds after running the function to see the elapsed time spent in the function. <?php … Continue reading
PHP Find time ago between two times
/** * Formats a timestamp nicely with an adaptive "x units of time ago" message. * Only handles past dates. * @return string Nicely-formatted message for the timestamp. * @param $time Output of strtotime() on your choice of timestamp. */ … Continue reading
Get file size and create time of file in PHP
All file have certain properties that can be displayed using PHP. These properties include the last access time, the last modified time, the last changed time, and the size of the file. Example: <HTML> <HEAD> <TITLE>Returning information about a file</TITLE> … Continue reading
XML-RPC Date/Time Data Type
An XML-RPC date/time data type is a primitive data type and specifies a date and a time value, up to the second. It follows the format YYYYMMDDTHH:MM:SS. using Year, month, day, hour, minute, and second conventions. The “T”, however, is … Continue reading
Calculate number of days between two given dates using PHP using strtotime?
The strtotime php function is used to parse any English textual datetime description into a Unix timestamp. This function will use the TZ environment variable (if available) to calculate the timestamp. It returns a timestamp on success, FALSE otherwise. Previous … Continue reading
PHP time – Get current datetime as an integer
The time function is used to obtain the current time from the operating system to second accuracy. Syntax: integer time () The return value is an integer equal to the seconds since midnight before January 1, 1970. Example code: <?php … Continue reading