duanjia6959 2018-06-12 12:36
浏览 119
已采纳

试图从日期对象获取年/月/日,但它返回1970-01-01

I'm trying to do an script that returns the year, month and day but the response is always the same : 1970-01-01.

I can't understand, it should change on every link and "google" ssl expiration date is not 1970-01-01

So, someone can see the error in the code?

$url           = "https://www.google.es/";
$orignal_parse = parse_url($url, PHP_URL_HOST);
$get           = stream_context_create(array(
    "ssl" => array(
        "capture_peer_cert" => TRUE
    )
));
$read     = stream_socket_client("ssl://" . $orignal_parse . ":443", $errno, $errstr, 30, STREAM_CLIENT_CONNECT, $get);
$cert     = stream_context_get_params($read);
$certinfo = openssl_x509_parse($cert['options']['ssl']['peer_certificate']);
$valid_to = date(DATE_RFC2822, $certinfo['validTo_time_t']);
$time     = strtotime($valid_to);
$month    = date("F",$time);
$year     = date('Y', $time);
$day      = date('j', $time);

if ($month = "Januay") {
    $month = "01";
} else if ($month = "February") {
    $month = "02";
} else if ($month = "March") {
    $month = "03";
} else if ($month = "April") {
    $month = "04";
} else if ($month = "May") {
    $month = "05";
} else if ($month = "June") {
    $month = "06";
} else if ($month = "July") {
    $month = "07";
} else if ($month = "August") {
    $month = "08";
} else if ($month = "September") {
    $month = "09";
} else if ($month = "October") {
    $month = "10";
} else if ($month = "November") {
    $month = "11";
} else if ($month = "December") {
    $month = "12";
}
$strtime = strtotime($day ."/" . $month . "/" . $year);
$newdate = date('Y-m-d',$strtime);
echo $newdate;
  • 写回答

2条回答 默认 最新

  • doudan4834 2018-06-12 12:51
    关注

    The strtotime function uses the character between the parts of the date to determine whether it is in American format or European format. Your call is using slashes so strtotime is looking for month/day/year but you are passing day/month/year. Try changing

    $strtime = strtotime($day ."/" . $month . "/" . $year);
    

    to

    $strtime = strtotime($month ."/" . $day . "/" . $year);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line