我不是php专家,在格式化.ics文件的日期时遇到了问题。
因此,我有一个循环,它为每个$post
生成一个日历条目(在我的情况下,$post是一个事件)
foreach( $posts as $post ) : setup_postdata($post);
$ical .= "BEGIN:VEVENT
UID:" . md5(uniqid(mt_rand(), true)) . "mysite.com
DTSTAMP:" . gmdate('Ymd').'T'. gmdate('His') . "Z
DTSTART:".get_event_date($post)."00Z
DTEND:".get_event_end_date($post)."00Z
SUMMARY:".get_the_title($post->ID)."
DESCRIPTION:".get_the_excerpt($post->ID)."
END:VEVENT";
endforeach;
我只是在格式化日期方面有问题,这就是为什么我完全去掉了它,希望你们能帮助我。
我有两个函数get_event_date($post)
和get_event_end_date($post)
,它们返回类似于1258665163
的时间戳。如何将此时间戳转换为iCal.ics文件的正确格式?
此外,我还想添加每个事件的time
。这两个函数被称为get_event_time($post)
和get_event_end_time($post)
,它们都以以下格式返回时间:11:00
或14:00
有人能帮我吗?我真的很感激你的帮助。
基本上,您希望将unix时间戳转换为iCal指定的格式。
php手册中有一条关于日期函数的精彩小评论,其中包括这个小宝石,正是这样做的:
// Converts a unix timestamp to iCal format (UTC) - if no timezone is
// specified then it presumes the uStamp is already in UTC format.
// tzone must be in decimal such as 1hr 45mins would be 1.75, behind
// times should be represented as negative decimals 10hours behind
// would be -10
function unixToiCal($uStamp = 0, $tzone = 0.0) {
$uStampUTC = $uStamp + ($tzone * 3600);
$stamp = date("Ymd'THis'Z", $uStampUTC);
return $stamp;
}
也许这会有所帮助。