用php中的unix时间填充日历
我正在创建一个表格日历,它每周工作一次。日历是这样的 我使用找到的代码设置标题日期。我的代码如下所示:用php中的unix时间填充日历,php,unix,calendar,Php,Unix,Calendar,我正在创建一个表格日历,它每周工作一次。日历是这样的 我使用找到的代码设置标题日期。我的代码如下所示: $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="re
$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>';
$dt=新日期时间;
$dt->setISODate($dt->format('o'),$dt->format('W');
$year=$dt->format('o');
$week=$dt->format('W');
$current_time=time();
$return.='
“.esc_html_uuuuuuuuuuuuuuuuuuuuuu('Hours'、'time_reservation')”;
做{
$return.=''.$dt->format('l')。
'.$dt->format('dmy');
$dt->修改(“+1天”);
}而($week==$dt->format('W');
$return.='';
对于($hour=8;$hour<23;$hour++){
$return.='';
$return.=''.$hour.':00';
对于($i=0;$i),可以使用strotime获得unixtimstamp:
<?php
$date = date("d M Y");
$time = "15:00";
$unixTime = strtotime($date . " " . $time);
?>
类似于:
$return .= '<td data-reservation_time="' . strtotime($dt->format("Y-m-d") . " " . $hour . ":00:00") . '"></td>';
$return.='';
为了获得时间戳,从$dt
对象中获取日期,从循环中获取时间。好的,所以答案比我想象的要简单。我仍然不能100%确定第一部分是绝对正确的,但它应该是(根据我的逻辑)
首先,创建本周的日期数组(curtesy of)
我的日期和时间都在数据时间
,适合jquery抓取:D这将在下周返回,而不是上表中的一周,我已经尝试过了:\I知道可以,但我需要在表中显示每个单元格的日期和时间。
$today = time();
if (date('D', $today) === 'Mon') {
$timestamp = strtotime('this Monday');
} else{
$timestamp = strtotime('last Monday');
}
$days = array();
$dates = array();
for ($i = 0; $i < 7; $i++) {
$days[] = strftime('%A <br /> %d %b %Y', $timestamp);
$dates[] = strftime('%d %b %Y', $timestamp);
$timestamp = strtotime('+1 day', $timestamp);
}
$return .= '<table class="reservation_time_table">
<tr><th>'.esc_html__('Hours', 'time_reservation').'</th>';
foreach ($days as $day => $day_value) {
$return .= '<th>'.$day_value.'</th>';
}
$return .= '</tr>';
for ($hour=8; $hour < 23 ; $hour++) {
$return .= '<tr>';
$return .= '<th>'.$hour.':00</th>';
foreach ($dates as $date => $date_value) {
$full_hour = $hour. ':00';
$return .= '<td data-time="'.strtotime($date_value. ' ' .$full_hour).'"></td>';
}
$return .= '</tr>';
}
$return .= '</table>';