PHP日期函数date格式化UNIX时间的方法

yipeiwu_com5年前PHP代码库

本文实例讲述了PHP日期函数date格式化UNIX时间的方法。分享给大家供大家参考。具体分析如下:

日期函数可以根据指定的格式将一个unix时间格式化成想要的文本输出

使用到函数语法如下

string date (string $Format);
string date (string $Format, int $Time);

下面是演示代码

<?php
echo "When this page was loaded,\n";
echo 'It was then ', date ('r'), "\n";
echo 'The currend date was ', date ('F j, Y'), "\n";
echo 'The currend date was ', date ('M j, Y'), "\n";
echo 'The currend date was ', date ('m/d/y'), "\n";
echo 'The currend date was the ', date ('jS \o\f M, Y'), "\n";
echo 'The currend time was ', date ('g:i:s A T'), "\n";
echo 'The currend time was ', date ('H:i:s O'), "\n";
echo date ('Y');
date ('L')?(print ' is'):(print ' is not');
echo " a leap year\n";
echo time ('U'), " seconds had elapsed since January 1, 1970.\n";
?>

输出结果如下

It was then Sat, 26 Dec 2009 07:09:51 +0000
The currend date was December 26, 2009
The currend date was Dec 26, 2009
The currend date was 12/26/09
The currend date was the 26th of Dec, 2009
The currend time was 7:09:51 AM GMT
The currend time was 07:09:51 +0000
2009 is not a leap year
1261811391 seconds had elapsed since January 1, 1970.

希望本文所述对大家的php程序设计有所帮助。

相关文章

PHP学习笔记(二) 了解PHP的基本语法以及目录结构

PHP学习笔记(二) 了解PHP的基本语法以及目录结构

通过这节课, 1.了解AppServ的目录结构 2.我们可以了解PHP的基本语法结构 1 我的AppServ安装目录是E盘: ①运用命令行的方式去操作apache服务器 apache服...

php设计模式 Mediator (中介者模式)

复制代码 代码如下: <?php /** * 中介者模式 * * 用一个中介对象来封装一系列的对象交互,使各对象不需要显式地相互引用从而使其耦合松散,而且可以独立地改变它们之间的交...

php中explode的负数limit用法分析

本文实例讲述了php中explode的负数limit用法。分享给大家供大家参考。具体分析如下: explode -- 使用一个字符串分割另一个字符串,使之成为数组。 参数为: arr...

详解PHP的Yii框架中自带的前端资源包的使用

Yii中的资源是和Web页面相关的文件,可为CSS文件,JavaScript文件,图片或视频等, 资源放在Web可访问的目录下,直接被Web服务器调用。 通过程序自动管理资源更好一点,例...

fsockopen pfsockopen函数被禁用,SMTP发送邮件不正常的解决方法

一:近期黑客利用程序漏洞注入后使用 fsockopen 进行PHPDDOS 攻击,导致部分服务器不稳定,现在将危险函数 fsockopen 暂时禁用,部分程序功能可能有问题,以下列出已知...