Tag Archive for time

Get Java Script Time

public static string GetJavaScriptTime()
{
Int64 retval = 0;
DateTime st = new DateTime(1970, 1, 1);
TimeSpan t = (DateTime.Now - st);
retval = (Int64)(t.TotalMilliseconds + 0.5);
retval = retval + 1000000;
return retval.ToString();
}

source

Get the time elapsed between two intervals

var foo = new Date();
var bar = new Date();
var baz = new Date();
baz.setTime(bar.getTime() - foo.getTime());
alert(baz.getMilliseconds() + " ms elapsed between the definition of foo and bar.");

source

using find to list old files based on date

find /var/log -mtime -14 -type f -exec ls -al {} ;

source

Time-stamp configuration

;;;Turn on time-stamp updating.  Timestamp must be in first 8 lines of file and look like:
;;;                Time-stamp: <>
(add-hook 'write-file-hooks 'time-stamp)

;;;;;;;;;;;;;;;;;;;;;;;;;
(setq time-stamp-format                 ; format of the stamp
;;use describe-variable for info
"[%f] modified by Noah Sussman on %:a, %:y.%02m.%02d at %02H : %02M : %02S on %s"
time-stamp-active t               ; update timestamps
time-stamp-warn-inactive t)       ; warn if unable

source

Translate amount of seconds to hours, minutes, seconds

Duration is a function used to turn seconds into a readable format, measured in weeks, days, hours, minutes and seconds.
Highlight: PHP

<?php
function duration($secs)
{
$vals = array('w' => (int) ($secs / 86400 / 7),
'd' => $secs / 86400 % 7,
'h' => $secs / 3600 % 24,
'm' => $secs / 60 % 60,
's' => $secs % 60);

$ret = array();

$added = false;
foreach ($vals as $k => $v) {
if ($v > 0 || $added) {
$added = true;
$ret[] = $v . $k;
}
}

return join(' ', $ret);
}
?>

Sample usage
Highlight: PHP

<?php
$dateOfBirth = $someTimestamp;
$ageInSeconds = time() - $dateOfBirth;

echo 'I am ' . duration($ageInSeconds) . ' old';
?>

source

php code exution time

// put this at the top of the page
$mtime = microtime();
$mtime = explode(" ",$mtime);
$mtime = $mtime[1] + $mtime[0];
$starttime = $mtime;

// put other code and html in here

// put this code at the bottom of the page
$mtime = microtime();
$mtime = explode(" ",$mtime);
$mtime = $mtime[1] + $mtime[0];
$endtime = $mtime;
$totaltime = ($endtime - $starttime);
echo "This page was created in ".$totaltime." seconds";

source

timestamp now

var now = Date.parse(new Date());

source

Delayed redirect

setTimeout( "window.location.href = 'http://walkerwines.com.au/'", 5*1000 );

source

Date

<?php
$time = date("Ymd H:i:s");
$year = date("Y");
echo ($time);
echo ($year);
?>

source