0

我有这个来自推特的日期,这代表了推文发布的确切日期,

Sun, 01 Jul 2012 19:05:54 +0000

我想要的是将其格式设置为 MM/DD HH:MM,试图寻找 php 日期格式,但找不到一种方法让它看起来完全符合我的要求。有人可以帮忙吗?谢谢。

4

2 回答 2

4
print date('m/d h:i',strtotime('Sun, 01 Jul 2012 19:05:54 +0000'));

The date function for php is a good place to find all sorts of information on this.

This would be pretty simple to search and figure it out. You are looking for a date... ahh, date, that is a php function. When you look that up you will see that it takes some params, a format and a time stamp. Well... You do not have a time stamp you have a string. how do i convert a string to time? Wait, there is a strtotime function in php. There you have it... run the date function in php with the way you want the date to look and then convert the string to timestamp with strtotime

于 2012-07-03T21:15:56.020 回答
0
<?php
    date_default_timezone_set("UTC");

    $string = "Sun, 01 Jul 2012 19:05:54 +0000";

    $timestamp = strtotime($string);

    print "Date is " . date("m/d H:i", $timestamp) . "\n";
?>

您可能需要更改时区和/或添加/减去秒数或使用本地时间函数在 TZ 之间进行转换。

于 2012-07-03T21:19:50.057 回答