php:写一个.ics(iCal)文件?日期格式? [英] php: writing a .ics (iCal) file? Date-formatting?
问题描述
我不是一个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文件?
此外,我还想添加 code>每个事件。
这两个函数都调用 get_event_time($ post)
和 get_event_end_time($ post)
时间,格式如下: 11:00
或 14:00
有人可以帮我吗?
基本上你想将一个unix时间戳转换为iCal指定的格式。 p>
在 php中有一个奇妙的小评论手动关于日期函数包括这个小宝石,正是这样:
//将unix时间戳转换为iCal格式(UTC) - 如果没有时区是
//指定,那么它假定uStamp已经是UTC格式。
// tzone必须为十进制,例如1小时45分钟将是1.75,后面
//时间应表示为负小数10小时后面
//将是-10
function unixToiCal($ uStamp = 0,$ tzone = 0.0){
$ uStampUTC = $ uStamp +($ tzone * 3600);
$ stamp = date(Ymd\ THis\Z,$ uStampUTC);
return $ stamp;
}
也许这有助。
I'm not much of a php expert and have troubles formatting the date for a .ics file.
So I have a loop that generates a calendar entry for each $post
(where a $post is an event in my case)
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;
I have just problems with formatting the date that's why I got completey rid of it and hope you guys might help me.
I have two functions get_event_date($post)
and get_event_end_date($post)
that return a timestamp like 1258665163
. How can I convert this timestamp into the right format for the iCal .ics file?
Moreover I'd also like to add the time
of each event.
Those two function are called get_event_time($post)
and get_event_end_time($post)
which both return a time in the following format: 11:00
or 14:00
Can somebody help me out here? I'd really appreciate some help.
Basically you want to convert a unix timestamp to the format specified for iCal.
There's a wonderful little comment in the php manual regarding the date function which includes this little jewel, doing exactly that:
// 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;
}
Maybe this helps.
这篇关于php:写一个.ics(iCal)文件?日期格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!