- 浏览: 355936 次
- 性别:
- 来自: 北京
文章分类
- 全部博客 (238)
- j2ee (22)
- mysql (14)
- hibernate (2)
- struts (3)
- spring (7)
- php (28)
- cakephp (12)
- pattern (0)
- 数据结构 (0)
- python (17)
- redis (1)
- sql (2)
- ibatis (1)
- jquery (3)
- 测试 (3)
- linux (37)
- solr (3)
- oracle (5)
- jira (5)
- 版本控制 (3)
- xp (1)
- IDE (3)
- apache (4)
- hadoop (2)
- freemarker (2)
- maven (5)
- 项目管理 (2)
- UML (1)
- Django (6)
- 正则 (1)
- Scrapy (1)
- 文档管理 (3)
- 项目集成 (8)
- MQ (3)
- 架构 (1)
- HTML (1)
- IT (1)
- 云 (0)
- 应用服务器 (4)
- win 7 (1)
- thrift (1)
- 学习 (3)
- OpenStack (3)
- sqlserver (1)
- javascript (1)
- zabbix (3)
- IOS (1)
- rabbitmq (1)
- springcloud (2)
最新评论
-
xushenkun4:
至今仍然有这个bug,0.9.1无法传输中文utf8。
thrift使用出现诡异问题 -
feiniao2029:
[i][/i][u][/u]引用
spring 配置init方法 -
wt811004:
非常感谢朋友慷慨指导
dotproject项目管理工具使用 -
hackpro:
这将是一个经典,就像大话西游...
javaeye怀旧 -
raymond2006k:
个人更偏好 Velocity。我觉得还有个对比点,就是编程方式 ...
jsp freemarker velocity 比较
Displaying the current date and time with the date() function
The most used function is one that returns the current date and time, and allows you to format as you wish - the date function. And using it is very simple:
date("formatting_option").
There are a whole range of possible formatting options. You can add your own characters inside the format string too. Here's a list of all the formatting characters.
Some examples:
displays:
The '-' characters are my formatting strings. I could have used anything else too:
displays:
displays:
Read through the list above - you'll find most possibilities have been thought of, and if all you're trying to do is format the date and/or time, you'll have no problems.
The date function is not only tied to displaying the local datetime on the server. You can also pass it a timestamp (often called a Unix timestamp, since it developed on Unix machines), which is the number of seconds since January 1, 1970 (starting with 1 second after midnight). By default the date function takes the current timestamp, but you can pass any timestamp you want, for example:
displays:
Be careful though with trying to use one of the reserved format strings as your own format string. If you tried to do something like:
you'd get something like the unexpected result of:
Of the first word, 'The', the 'T' returns the time zone setting of the machine running PHP (SAST in my case), 'h' returns the hour, while at least the 'e' comes though correctly. But from there it's all downhill. In order to get the correct display, you'll need to escape the characters with a backslash, as follows:
which displays what we'd originally hoped for:
Just for good measure we had to escape the 't' twice, since '\t' is the special character for a tab. Not the easiest to read at all! Later in this article, we look at the strftime() function, which makes formatting complex strings easier, and also helps with other languages.
There is also a related gmdate() function, which is the same as date(0 except that it returns the Greenwich Mean Time.
The most used function is one that returns the current date and time, and allows you to format as you wish - the date function. And using it is very simple:
date("formatting_option").
There are a whole range of possible formatting options. You can add your own characters inside the format string too. Here's a list of all the formatting characters.
a "am" or "pm" A "AM" or "PM" B Swatch Internet time d day of the month, 2 digits with leading zeros; i.e. "01" to "31" D day of the week, textual, 3 letters; i.e. "Fri" F month, textual, long; i.e. "January" g hour, 12-hour format without leading zeros; i.e. "1" to "12" G hour, 24-hour format without leading zeros; i.e. "0" to "23" h hour, 12-hour format; i.e. "01" to "12" H hour, 24-hour format; i.e. "00" to "23" i minutes; i.e. "00" to "59" I (capital i) "1" if Daylight Savings Time, "0" otherwise. j day of the month without leading zeros; i.e. "1" to "31" l (lowercase 'L') day of the week, textual, long; i.e. "Friday" L boolean for whether it is a leap year; i.e. "0" or "1" m month; i.e. "01" to "12" M month, textual, 3 letters; i.e. "Jan" n month without leading zeros; i.e. "1" to "12" r RFC 822 formatted date; i.e. "Thu, 21 Dec 2000 16:01:07 +0200" (added in PHP 4.0.4) s seconds; i.e. "00" to "59" S English ordinal suffix, textual, 2 characters; i.e. "th", "nd" t number of days in the given month; i.e. "28" to "31" T Timezone setting of this machine; i.e. "MDT" U seconds since the epoch w day of the week, numeric, i.e. "0" (Sunday) to "6" (Saturday) Y year, 4 digits; i.e. "1999" y year, 2 digits; i.e. "99" z day of the year; i.e. "0" to "365" Z timezone offset in seconds (i.e. "-43200" to "43200"). The offset for timezones west of UTC is always negative, and for those east of UTC is always positive.
Some examples:
//returns the day (0-31), month (3 letters) and year(4 digits) print date("d-M-Y");
displays:
09-May-2002
The '-' characters are my formatting strings. I could have used anything else too:
print date("d^^^M^^^Y");
displays:
09^^^May^^^2002
print date("D dS M,Y h:i a");
displays:
Thu 09th May,2002 06:13 pm
Read through the list above - you'll find most possibilities have been thought of, and if all you're trying to do is format the date and/or time, you'll have no problems.
The date function is not only tied to displaying the local datetime on the server. You can also pass it a timestamp (often called a Unix timestamp, since it developed on Unix machines), which is the number of seconds since January 1, 1970 (starting with 1 second after midnight). By default the date function takes the current timestamp, but you can pass any timestamp you want, for example:
print date("l M dS, Y, H:i:s",5678)
displays:
Thursday Jan 01st, 1970, 03:34:38
Be careful though with trying to use one of the reserved format strings as your own format string. If you tried to do something like:
print date("The time is: H.i");
you'd get something like the unexpected result of:
SAST11e 314605e 4638: 23.46
Of the first word, 'The', the 'T' returns the time zone setting of the machine running PHP (SAST in my case), 'h' returns the hour, while at least the 'e' comes though correctly. But from there it's all downhill. In order to get the correct display, you'll need to escape the characters with a backslash, as follows:
print date("\T\he \\t\i\m\e \i\s: H.i");
which displays what we'd originally hoped for:
The time is: 23.54
Just for good measure we had to escape the 't' twice, since '\t' is the special character for a tab. Not the easiest to read at all! Later in this article, we look at the strftime() function, which makes formatting complex strings easier, and also helps with other languages.
There is also a related gmdate() function, which is the same as date(0 except that it returns the Greenwich Mean Time.
发表评论
-
MAC 安装php+nginx支持oci8等
2015-07-15 10:41 14821. 安装 php brew install php55 ... -
浏览器自动识别编码问题
2012-06-27 17:03 881由于web应用页面编码使用的gbk,但web服务器php的编码 ... -
PHP PACK UNPACK用法
2011-01-25 10:02 1588Pack 与unpack使用说明: ... -
百万级PHP网站架构方案
2010-11-04 18:09 1399在了解过世界最大的PHP ... -
PHP unzip 解压文件
2010-11-03 14:19 9751.unzip <?php $zip ... -
Php防止重复提交问题总结
2010-10-28 14:46 2575用户提交表单时可能因为网速的原因,或者网页被恶意刷新,致使同一 ... -
借用Google API 写一个查看天气预报的类
2010-10-28 13:09 1001<? //- Describe: //- Autho ... -
php当前日期的加减操作
2010-10-26 09:29 1985<?php echo "Today:" ... -
PHP 的命令行模式
2010-09-17 10:31 1249PHP 的命令行模式 从版本 4.3.0 开始,PHP 提供 ... -
php soap 错误处理(精简版)
2010-09-17 10:27 19841.使用soap $client = &qu ... -
php soap client 链接问题
2010-09-16 16:04 23441.说明 php 调用jira的soap接口代码: ... -
Handling data in a PHP JSON Object
2010-09-08 14:16 1155Trends data from Twitter Search ... -
php 和 js 保留2位小数
2010-08-24 10:25 27961.php保留两位小数例子 四舍五入 A.nu ... -
zlib 文件操作
2010-08-23 13:44 1002<?php //Extracting the co ... -
php pathinfo()函数用法详解
2010-08-23 12:59 1207摘要: php pathinfo()函数用法详解,pathin ... -
Php学习《五》 ------ 基本知识摘录
2010-08-17 15:31 9591.php中文字符串长度及定长截取问题 使用str_len( ... -
Php学习《四》 ------ 文件上传
2010-08-03 17:29 806通过 PHP,可以把文件上传到服务器。 创建一个文件上传表单 ... -
Php学习《三》 ------ 文件处理
2010-08-03 17:16 801fopen() 函数用于在 PHP 中 ... -
Php学习《二》 ------循环
2010-08-03 17:09 803循环 在您编写代码时,您经常需要让相同的代码块运行很多次。您 ... -
Php学习《一》 ------数组
2010-08-03 16:58 8111.数组分类 a.带值 ...
相关推荐
php报时区错误,按照网上说的改时间date.timezone根本不管用!怎么解决,看我的.zip Warning: phpinfo() [function.phpinfo]: It is not safe to rely on the system's timezone settings. You are *required* to use ...
Chapter 19 Managing the Date and Time Chapter 20 Internationalization and Localization Chapter 21 Generating Images Chapter 22 Using Session Control in PHP Chapter 23 Integrating JavaScript and PHP ...
Chapter 12: Date and Time Chapter 13: Forms Chapter 14: Authenticating Your Users Chapter 15: Handling File Uploads Chapter 16: Networking Chapter 17: Session Handlers Chapter 18: Web Services Chapter...
8 怎样设计的问题:日期和时间处理 (Design how-to: date and time handling) Part 2: 测试和重构 (Testing and refactoring) 9 测试驱动开发 (Test-driven development) 10 高级测试技术 (Advanced testing ...
19 Managing the Date and Time 20 Internationalization and Localization 21 Generating Images 22 Using Session Control in PHP 23 Integrating JavaScript and PHP 24 Other Useful Features Part V: Building...
在写php程序中有时会出现这样的警告: PHP Warning: date(): It is not safe to rely on the system’... In case you used any of those methods and you are still getting this warning, you most likely misspelled
echo "Current date and time is: $date"; ``` 3. 函数 exec() 和 passthru() 在PHP的安全模式下,反引号运算符可能不可用,这时可以使用`exec()`函数。`exec()`接受命令作为参数,执行它,并返回命令输出的最后一...
Chapter 8: Working with Date/Time and International Aspects Chapter 9: Developing Middleware Chapter 10: Looking at Advanced Algorithms Chapter 11: Implementing Software Design Patterns Chapter 12: ...
driven mobile app development, powerful features like local storage and WebSockets, superb audio and video APIs, and new layout options using CSS3, SVG, and Canvas, HTML5 has entered its prime time. ...
TTL for user-defined php.ini files (time-to-live) in seconds. Default is 300 seconds (5 minutes) ;user_ini.cache_ttl = 300 ;;;;;;;;;;;;;;;;;;;; ; Language Options ; ;;;;;;;;;;;;;;;;;;;; ; Enable ...
In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'UTC' for '8.0/noDST' instead"。这段信息指出了时区设置的...
Let's make sure we all get home on time and sleep well at night. Topics This is a quick read, at just over 100 pages. This is a handbook style guide to specific items you can act on. The following ...
在php程序开发中有时会出现类似于这样的警告: PHP Warning: date(): It is not safe to rely on the ... In case you used any of those methods and you are still getting this warning, you most likely missp
The selection of PHP for website development is advantageous due to its low cost, fast speed, and my familiarity with the technology, eliminating the need for additional learning time. Therefore, the ...
In this tutorial, we'll cover some of the basics of Unicode-encoded text and Unicode files, and how to view and manipulate it in UltraEdit. Search and delete lines found UEStudio and UltraEdit provide...
出在 the Internet. For instance, if someone ... With its user-friendly interface and real-time information updates, it contributes to a more enjoyable and well-managed sports environment for all users.
If you are a data scientist of any level, beginners included, and interested in cleaning up your data, this is the book for you! Experience with Python or PHP is assumed, but no previous knowledge of ...