Is there a way to get the current timestamp

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
myleow
Forum Contributor
Posts: 194
Joined: Mon Jun 21, 2004 7:05 pm
Location: California

Is there a way to get the current timestamp

Post by myleow »

Is there a way to get the current timestamp without using

Code: Select all

$current_timestamp = date('c');
? I am not using PHP5.

I am using PHP 4.1.2 so if there is a way please provide me with the example to do so.

Regards
Mian
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Code: Select all

<?php

function getISO8601($time = false)
{
if(!is_int($time))
  $time = time();

$offset = date('O',$time);
$len = strlen($offset);
$offset .= $offset{$len-1};
$offset{$len-1} = $offset{$len-2};
$offset{$len-2} = ':';
return date('Y-m-d\TH:i:s',$time) . $offset;
}

echo getISO8601();

?>
outputs

Code: Select all

2004-08-17T15:42:23-07:00
for my local machine :)
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

[php_man]time[/php_man]()

Code: Select all

$curr_time = time();
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply