views:

33

answers:

1
$ts = time();

How to convert $ts to the format 09/02/2010 ?

+5  A: 

Look at the date() function: http://au2.php.net/manual/en/function.date.php. You'd want either:

date('d/m/Y', $ts)

or:

date('m/d/Y', $ts)

Depending on the format you need ("09/02/2010" is ambiguous, it could be either).

Daniel15
Seems seconds is lot easier to deal with in PHP than unix timestamps,right?
wamp
@wamp What do you mean by that? Unix timestamps are the number of seconds since the Unix epoch (1st January 1970). See http://en.wikipedia.org/wiki/Unix_time for more information on that.
Daniel15
It depends on what you're doing with your timestamp. As a rule, you *absolutely should not* be doing arithmetic on a seconds-based timestamp because you will come a cropper eventually with things like daylight-saving. Use the inbuilt date manipulation functions instead.
staticsan
What's the difference between unix timestamps and `time()` ?
wamp
@wamp Unix timestamps are what time() returns, there is no difference :)
Daniel15