伍佰目录 短网址
  当前位置:海洋目录网 » 站长资讯 » 站长资讯 » 文章详细 订阅RssFeed

PHP - Manual: date_format

来源:网络转载 浏览:52次 时间:2023-08-09
date_get_last_errors » « date_diff PHP 手册 函数参考 日期与时间相关扩展 日期/时间 Date/Time 函数

date_format

(PHP 5 >= 5.2.0, PHP 7, PHP 8)

date_format — 别名 DateTime::format()

说明

此函数是该函数的别名: DateTime::format()

add a note

User Contributed Notes 3 notes

up down 81 Andrew Gregory12 years ago Requirements: PHP5+

To expand on Matt Walsh's example, a simple way to get eBay, or Amazon, web service timestamps is as follows:

<?php

$current_time = urlEncode(subStr(date("c"), 0, 19)."Z");

?>

In other words, take the date/time of now (in ISO 8601 format), discard the trailing Daylight Savings Time specifier, add a "Z" where the DST was and urlEncode the whole thing to convert the time's colons for REST requests (required for amazon, not sure about eBay).

Another way might be to create your own timestamp:

<?php

$current_time = urlEncode(date("Y-m-d")."T".date("H:i:s")."Z");

?>

This way however takes a little more coding on the line.

As far as performance goes, I'm not sure which may be quicker. I just like things to work and work well, don't much care for how fast they are as long as they get the job done :)

A much simpler way to get the eBay, or Amazon, web service timestamp is as follows:

<?php

$current_date = gmDate("Y-m-d\TH:i:s\Z");

?>

Enjoy!
up down -42 Matt Walsh15 years ago The ISO8601 output format doesn't jive with (at least) what eBay expects in its SOAP transactions.  eBay wants a UTC time with a 'Z' suffix.   That is, eBay (and I'm guessing other web services) will accept "2007-05-04T17:01:17Z" but not "2007-05-04T17:01:17+0000".  As it is, the built-in DateTime::ISO8601 format uses the +0000 timezone specifier even when in a UTC timezone.

As a workaround, I do this:

<?php
   function get_ebay_UTC_8601(DateTime $time)
   {  $t = clone $time;
      $t->setTimezone(new DateTimeZone("UTC"));
      return $t->format("Y-m-d\TH:i:s\Z");
   }
?>
up down -63 Mike C13 years ago If you are studying date_format because you want to format a date, consider the power of date(..) !!!!

the mktime article has an example of adding days to a date of your choice and then formatting it:
echo date("M-d-Y", mktime(0, 0, 0, 12, 32, 1997))
where the 32 is like adding 1 day to the 31st .
add a note

官方地址:https://www.php.net/manual/en/function.date-format.php

  推荐站点

  • At-lib分类目录At-lib分类目录

    At-lib网站分类目录汇集全国所有高质量网站,是中国权威的中文网站分类目录,给站长提供免费网址目录提交收录和推荐最新最全的优秀网站大全是名站导航之家

    www.at-lib.cn
  • 中国链接目录中国链接目录

    中国链接目录简称链接目录,是收录优秀网站和淘宝网店的网站分类目录,为您提供优质的网址导航服务,也是网店进行收录推广,站长免费推广网站、加快百度收录、增加友情链接和网站外链的平台。

    www.cnlink.org
  • 35目录网35目录网

    35目录免费收录各类优秀网站,全力打造互动式网站目录,提供网站分类目录检索,关键字搜索功能。欢迎您向35目录推荐、提交优秀网站。

    www.35mulu.com
  • 就要爱网站目录就要爱网站目录

    就要爱网站目录,按主题和类别列出网站。所有提交的网站都经过人工审查,确保质量和无垃圾邮件的结果。

    www.912219.com
  • 伍佰目录伍佰目录

    伍佰网站目录免费收录各类优秀网站,全力打造互动式网站目录,提供网站分类目录检索,关键字搜索功能。欢迎您向伍佰目录推荐、提交优秀网站。

    www.wbwb.net