date() 函数

  功能:用于格式化时间,返回一个字符串。 

  语法:string date( string format [, int timestamp] ),其中参数 format 表示时间格式化的方式;可选参数timestamp表示时间戳,默认为time(),即当前时间。

时间格式化的方式

格式化方式 说明
Y 4位数字年,y为2位数字,如99即1999年
m 数字月份,前面有前导0,如01。n 为无前导0数字月份
F 月份,完整的文本格式,例如 January 或者 March
M 三个字母缩写表示的月份,例如 Jan 或者 Mar
d 月份中的第几天,前面有前导0,如03。j 为无前导0的天数
w 星期中的第几天,以数字表示,0表示星期天
z 年份中的第几天,范围0-366
W 年份中的第几周,如第32周
H 24小时格式,有前导0,h为12小时格式
G 24小时格式,无前导0,g为对应12小时格式
i 分钟格式,有前导0
s 秒格式,有前导0
A 大写上下午,如AM,a为小写

例子一

date("Y-m-d");               //显示格式如 2008-12-01
date("Y-m-d",time()); //显示格式如 2008-12-01
date("Y.m.d",time()); //显示格式如 2008.12.01
date("M d Y",time()); //显示格式如 Dec 01 2008
date("Y-m-d H:i",time()); //显示格式如 2008-12-01 12:01

例子二

<?php
$date=date_create("2016-09-25");
echo date_format($date,"Y/m/d H:i:s");
?>
  1. date_default_timezone_set('PRC');
  2. $start_time ="2017-3-22 17:00:00";//开始考试时间
  3. echo $start_time."";
  4. $mm =60*60;//PHP的时间是按秒算的
  5. echo date("Y-m-d H:i:s",strtotime($start_time)+$mm);

如果输出的时间和实际时间差8个小时(假设采用的北京时区)的话,检查php.ini文件,做如下设置:date.timezone = PRC

[参考] http://www.5idev.com/p-php_time_date.shtml

PHP 格式化显示时间 date() 函数【转】的更多相关文章

  1. PHP 格式化显示时间 date()函数

    Y 4位数字年,y为2位数字,如99即1999年 m 数字月份,前面有前导0,如01.n 为无前导0数字月份 F 月份,完整的文本格式,例如 January 或者 March M 三个字母缩写表示的月 ...

  2. php获得当前日期时间 date函数

    time()得到从1970-01-01到现在共走了多少秒 要找出前一天的时间就是 time()-60*60*24; 要找出前一年的时间就是 time()*60*60*24*365 那么如何把这个数字换 ...

  3. C 格式化显示时间(time.h)

    转自:http://www.cnblogs.com/xudong-bupt/p/3550157.html C/C++程序中需要程序显示当前时间,可以使用标准函数strftime. 函数原型:size_ ...

  4. Beego在views中格式化显示时间(int64转string)

    最近在使用beego开发系统的过程中,遇到时间转换问题,需求如下: 通过以下函数获取Unix时间戳,后台数据库格式为int64: time.Now().Unix() 效果图: 从数据库获取数据,直接以 ...

  5. js 中格式化显示时间

    function getMyDateTime(str){ var oDate = new Date(str), oYear = oDate.getFullYear(), oMonth = oDate. ...

  6. JS 封装一个显示时间的函数

    s(); function s (){ var mydate=new Date(); var y = mydate.getFullYear(); var m = mydate.getMonth(); ...

  7. EasyUI datagrid 格式化显示数据

    http://blog.163.com/ppy2790@126/blog/static/103242241201512502532379/ 设置formatter属性,是一个函数,格式化函数有3个参数 ...

  8. js 格式化时间日期函数小结

    下面是脚本之家为大家整理的一些格式化时间日期的函数代码,需要的朋友可以参考下. 代码如下: Date.prototype.format = function(format){ var o = { &q ...

  9. PHP date函数时间相差8个小时解决办法

    php中date时间相差8个小时的解决办法 作者: PHP中文网|标签:|2016-7-25 08:46 在Windows上,在默认的PHP配置下,date函数返回的时间值和当地时间总是相差8小时,即 ...

随机推荐

  1. Oracle告Google输了

    Oracle告Google输了 boxi • 2016-05-27 • 大公司 Google表示,陪审团的认定代表了Android生态体系.Java开发社区以及依靠开放免费编程语言开发创新消费者产品的 ...

  2. Java8——Stream

    /* * 一.Stream API 的操作步骤: * * 1. 创建 Stream * * 2. 中间操作 * * 3. 终止操作(终端操作) */ public class TestStreamaA ...

  3. MyEclipse一直building workspace

    点击Project,点击Bulid Automatically去掉其前面的勾,即取消自动编译工作空间中的所有java文件. 注:不要取消!!!!取消之后如果你修改的java文件和struts.xml等 ...

  4. Node.js 入门篇

    Node.js 使用C++开发的. Node.js是一个事件驱动服务端JavaScript环境,只要能够安装相应的模块包,就可以开发出需要的服务端程序,如HTTP服务端程序.Socket程序等. No ...

  5. [LeetCode] 854. K-Similar Strings 相似度为K的字符串

    Strings A and B are K-similar (for some non-negative integer K) if we can swap the positions of two ...

  6. [LeetCode] 658. Find K Closest Elements 寻找K个最近元素

    Given a sorted array, two integers k and x, find the k closest elements to x in the array. The resul ...

  7. android 完全退出实现

    实现方法是在application中定义一个集合存储所有的Activity对象,在Activity创建时添加进集合中,在程序退出时,finish掉所有的Activity即可. 步骤如下: 1.自定义A ...

  8. Error running 'xxx': Command line is too long. Shorten command line for xxx

    跑单元测试时,报错如下: Error running 'xxx': Command line is too long. Shorten command line for xxx 解决方案: 在项目所在 ...

  9. idea创建maven多模块Spring Boot项目

    1, 创建父项目 1.1,file - new - project 1.2,选择maven,Create from archetype(有的说不选,有的没说,不过我建父项目的时候没有勾选) 1.3,根 ...

  10. mysql 基本操作 四

    1.临时表 当绘画结束时,临时表会自动销毁,无法用show tables 查看 临时表. MariaDB [jason]> create temporary table tmp(pro ),ci ...