gpt4 book ai didi

php - 在 php 中用 unix 时间填充日历

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:49:43 24 4
gpt4 key购买 nike

我正在创建一个每周工作的日历表。日历看起来像这样

enter image description here

我使用了找到的代码 here设置我的标题日期。我的代码如下所示:

$dt = new DateTime;
$dt->setISODate($dt->format('o'), $dt->format('W'));
$year = $dt->format('o');
$week = $dt->format('W');
$current_time = time();

$return .= '<table class="reservation_time_table">
<tr><th>'.esc_html__('Hours', 'time_reservation').'</th>';
do {
$return .= '<th>' . $dt->format('l') . '<br>' . $dt->format('d M Y') . '</th>';
$dt->modify('+1 day');
} while ($week == $dt->format('W'));
$return .= '</tr>';
for ($hour=8; $hour < 23 ; $hour++) {
$return .= '<tr>';
$return .= '<th>'.$hour.':00</th>';
for ($i=0; $i <7 ; $i++) {
$return .= '<td data-reservation_time=""></td>';
}
$return .= '</tr>';
}

$return .= '</table>';

现在,我需要在 data-reservation_time 中输入 Unix 格式的日期(这就是为什么有 $current_time 变量),那个细胞。因此,例如在 20 日星期五 8:00 的单元格中,该单元格中应该有 1448006400。稍后我将使用它存储在数据库中。

但是我该怎么做呢?我被困在这一点上。感谢您的帮助。

编辑

找到了答案。它在下面:)

最佳答案

您可以使用 strtotime 获取 unixtimstamp:

<?php
$date = date("d M Y");
$time = "15:00";
$unixTime = strtotime($date . " " . $time);
?>

关于php - 在 php 中用 unix 时间填充日历,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33806757/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com