Tag Archive for time

Show Current Date

<?php

// Value of how many hours offset from server and local time
$hourdiff = "3";

// Offsetting time by seconds
$timeadjust = ($hourdiff * 3600);

// Format of date which will be displayed
$currentdate = date("l m/d/y",time() - $timeadjust);

// Display the output
print ("$currentdate");

?>

source

Millisecond Equivalent of Time Interval

//Gets the millisecond equivalent of an interval
//Example: (2).seconds() == 2000
Number.prototype.seconds = function(){ return this * 1000; };
Number.prototype.minutes = function(){ return this * 60000; };		//60 * 1000
Number.prototype.hours = function(){ return this * 3600000; };		//60 * 60 * 1000
Number.prototype.days = function(){ return this * 86400000; };		//24 * 60 * 60 * 1000
Number.prototype.weeks = function(){ return this * 604800000; };	//7 * 24 * 60 * 60 * 1000

source

Linux Rename File to Current Date/Time

mv filename "`date +%Y%m%d_%H`_filename"

source

Set PHP time limit for script execution to infinity

<?php
if (!get_cfg_var('safe_mode')) {
set_time_limit(0);
}
?>

source

getMicroTime

function getmicrotime(){
list($usec, $sec) = explode(" ",microtime());
return ((float)$usec + (float)$sec);
}

source

List commands in history, sorted by usage

history  | awk '{a[$2]++}END{for(i in a){print a[i] " " i}}' | sort -rn | head

# Full sousveillance version:
history | awk '{a[$2 " " $3 " " $4 " " $5]++}END{for(i in a){print a[i] " " i}}' | sort -rn | head -n+25

source

Calculating script execution time

<?php
$start = (float) array_sum(explode(' ',microtime()));

// put you code that wanted to render at here

$end = (float) array_sum(explode(' ',microtime()));

echo "Processing time: ". sprintf("%.4f", ($end-$start))." seconds";
?>

source

Days ago function

// convert a date into a string that tells how long ago that date was.... eg: 2 days ago, 3 minutes ago.
function ago($d) {
$c = getdate();
$p = array('year', 'mon', 'mday', 'hours', 'minutes', 'seconds');
$display = array('year', 'month', 'day', 'hour', 'minute', 'second');
$factor = array(0, 12, 30, 24, 60, 60);
$d = datetoarr($d);
for ($w = 0; $w < 6; $w++) {
if ($w > 0) {
$c[$p[$w]] += $c[$p[$w-1]] * $factor[$w];
$d[$p[$w]] += $d[$p[$w-1]] * $factor[$w];
}
if ($c[$p[$w]] - $d[$p[$w]] > 1) {
return ($c[$p[$w]] - $d[$p[$w]]).' '.$display[$w].'s ago';
}
}
return '';
}

// you can replace this if need be. This converts my dates returned from a mysql date string into
//   an array object similar to that returned by getdate().
function datetoarr($d) {
preg_match("/([0-9]{4})(-)([0-9]{2})(-)([0-9]{2}) ([0-9]{2})(:)([0-9]{2})(:)([0-9]{2})/", $d, $matches);
return array(
'seconds' => $matches[10],
'minutes' => $matches[8],
'hours' => $matches[6],
'mday' => $matches[5],
'mon' => $matches[3],
'year' => $matches[1],
);
}

source

Simple Days Since

<?php
function days_since ($time) {
$startdate   = strtotime($time);
$presentdate = time();
$days = round(($presentdate - $startdate)/86400);
return $days;
}
?>

source

Set date Function Timezone

<?php
date_default_timezone_set('US/Central');
?>

source