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 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化