Хорошо.Функция завершена.Он принимает метку времени Unix и возвращает YYYY-MM-DD.Это было все, что мне было нужно.Надеюсь, это кому-нибудь поможет ...
<?php
$t=1325522004;//return 2011-09-19
/*
* Transform a Unix Timestamp to ISO 8601 Date format YYYY-MM-DD
* @param unix timestamp
* @return Returns a formated date (YYYY-MM-DD) or false
*/
function unixToIso8601($timestamp){
if($timestamp<0){return false;}//Do not accept negative values
/* Too many constants, add this to a class to speed things up. */
$year=1970;//Unix Epoc begins 1970-01-01
$dayInSeconds=86400;//60secs*60mins*24hours
$daysInYear=365;//Non Leap Year
$daysInLYear=$daysInYear+1;//Leap year
$days=(int)($timestamp/$dayInSeconds);//Days passed since UNIX Epoc
$tmpDays=$days+1;//If passed (timestamp < $dayInSeconds), it will return 0, so add 1
$monthsInDays=array();//Months will be in here ***Taken from the PHP source code***
$month=11;//This will be the returned MONTH NUMBER.
$day;//This will be the returned day number.
while($tmpDays>=$daysInYear){//Start adding years to 1970
$year++;
if(isLeap($year)){
$tmpDays-=$daysInLYear;
}
else{
$tmpDays-=$daysInYear;
}
}
if(isLeap($year)){//The year is a leap year
$tmpDays--;//Remove the extra day
$monthsInDays=array(-1,30,59,90,120,151,181,212,243,273,304,334);
}
else{
$monthsInDays=array(0,31,59,90,120,151,181,212,243,273,304,334);
}
while($month>0){
if($tmpDays>$monthsInDays[$month]){
break;//$month+1 is now the month number.
}
$month--;
}
$day=$tmpDays-$monthsInDays[$month];//Setup the date
$month++;//Increment by one to give the accurate month
return $year.'-'.(($month<10)?'0'.$month:$month).'-'.(($day<10)?'0'.$day:$day);
}
function isLeap($y){
return (($y)%4==0&&(($y)%100!=0||($y)%400==0));
}
echo unixToIso8601($t);
?>