如何将此特定时间转换为此处的时间


How do I convert this specific time into the one here?

我正在从使用此时间格式的网站中抓取数据:

星期六,二月7,2015和在另一个地方,他们提到小时,例如12:45。

我设法将它们放在一个字符串中,如下所示:2015年2月7日 12:45, 星期六

但是我的SQL表中的时间数据如下:2015-01-13 09:49:43.000000

我正在使用 strtotime 将数据插入数据库。我的代码如下所示:

$dateTime=$date.$time.''; 

当我打印$dateTime时,我得到"2015年2月7日星期六17:30"。当我手动将其放入 strtotime 时,它效果很好。但是,如果我将$dateTime发送到 strtotime,它会失败并给出默认的 1970 时间。我已经仔细检查了它的类型是否为字符串。

我喜欢使用PHP的DateTime类,这里有一个例子。

$newdate = new DateTime($yourdate);
$date = $newdate->format('Y-m-d H:i:s');
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");
$stmt = $mysqli->prepare("UPDATE table SET column = ? WHERE row = ?")
$stmt->bind_param("ss", $date, $row);
$stmt->execute();

编辑:
因此,您没有从抓取的网站获得格式正确的日期,而是 HTML。我建议使用 JQuery 来处理这个问题。

以下是您获得的内容:

<th colspan="3" class="comp-date"> Saturday, February 7, 2015</th><td class="status"> 17:30</td>

我们可以获取类名所需的信息,下面的代码需要进入 PHP 文件。

<?php
    $scrapedDate = ....;
?>
<html>
<head>
//add JQuery to the <head> section//
<script src="//code.jquery.com/jquery-1.11.2.min.js"></script>
<script>
$(function() {
    $scraped = '<?= $scrapedDate ?>'; //get data from PHP//
    $scrapedDate = $($scraped).closest('.comp-date').text().trim();
    $scrapedTime = $($scraped).closest('.status').text();
    $dateTime = $scrapedDate+$scrapedTime;
    alert($dateTime);
    return false;
});
</script>
</head>

我对此进行了测试,它可以工作,但是,完成此操作后,您需要将其恢复为PHP,您可以使用AJAX执行此操作。

Date('Y-m-d h:i:s', strtotime($datestring));

你是如何构建你的$dateTime字符串的?你能发布代码吗?看起来你得到了答案的一半

像这样: $dateTime = $day.",".$month.",".$year;