动态创建.ics文件 [英] Create .ics file dynamically

查看:489
本文介绍了动态创建.ics文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为客户建立了一个网站,他们可以在此发布事件.与其为每个事件从iCal手动创建.ics文件并上载它,不如将它从数据库中拉出并使用PHP自动自动创建.ics文件,这是更好的选择.

I made a website for a client where they can post events. Instead of manually creating .ics files from iCal for every event and uploading it, I though it would be better to pull it out of the database and automatically create a .ics file automatically with PHP.

我可以从数据库中提取信息(没问题),但是当将其转换为日历文件的时间戳时,这很困难.这是我存储在数据库中的内容:

I can pull information from the database (no problem), but when converting it to a time stamp for the calendar file it a tough one. Here's what I store in the database:

Month: 05
Day: 02
Year: 2011
Time: 11:30am - 1:30pm

以下是创建我的.ics文件的代码:

Here's the code to create my .ics files:

//This is the most important coding.
header("Content-Type: text/Calendar");
header("Content-Disposition: inline; filename=adamhouston_$id.ics");

echo "BEGIN:VCALENDAR\n";
echo "PRODID:-//Microsoft Corporation//Outlook 12.0 MIMEDIR//EN\n";
echo "VERSION:2.0\n";
echo "METHOD:PUBLISH\n";
echo "X-MS-OLK-FORCEINSPECTOROPEN:TRUE\n";
echo "BEGIN:VEVENT\n";
echo "CLASS:PUBLIC\n";
echo "CREATED:20091109T101015Z\n";

echo "DESCRIPTION:Speaker: $event_query_row[speaker_name]\\n\\nTopic: $event_query_row[speaker_topic]\n";
echo "DTEND:20100208T040000Z\n";
echo "DTSTAMP:20100109T093305Z\n";
echo "DTSTART:20100208T003000Z\n";
echo "LAST-MODIFIED:20091109T101015Z\n";
echo "LOCATION:$event_query_row[location]\n";
echo "PRIORITY:5\n";
echo "SEQUENCE:0\n";
echo "SUMMARY;LANGUAGE=en-us:ADAM-Houston Event\n";
echo "TRANSP:OPAQUE\n";
echo "UID:040000008200E00074C5B7101A82E008000000008062306C6261CA01000000000000000\n";
echo "X-MICROSOFT-CDO-BUSYSTATUS:BUSY\n";
echo "X-MICROSOFT-CDO-IMPORTANCE:1\n";
echo "X-MICROSOFT-DISALLOW-COUNTER:FALSE\n";
echo "X-MS-OLK-ALLOWEXTERNCHECK:TRUE\n";
echo "X-MS-OLK-AUTOFILLLOCATION:FALSE\n";
echo "X-MS-OLK-CONFTYPE:0\n";
//Here is to set the reminder for the event.
echo "BEGIN:VALARM\n";
echo "TRIGGER:-PT1440M\n";
echo "ACTION:DISPLAY\n";
echo "DESCRIPTION:Reminder\n";
echo "END:VALARM\n";
echo "END:VEVENT\n";
echo "END:VCALENDAR\n";

现在如何将数据库中的数据转换为正确的时间/日期戳?

Now how do I convert the data in my database to a correct time/date stamp?

推荐答案

iCal时间存储在UTC中,而不是存储在它们起源的时区中,除非另有说明(请参见编辑)

iCal times stored in UTC and not in the time zone that they originated in unless otherwise specified (see edit)

如果您希望代码通用,则还需要存储时区.如果您确实想要...,可以对转换进行硬编码.

If you want your code to be generic, you'll need to store the time zone as well. If you really want to... you can hard code in the conversion.

我也建议不要以这种格式存储时间:

I would also recommend not storing time in this format:

 Month: 05
 Day: 02 
 Year: 2011
 Time: 11:30am - 1:30pm

,然后移至时间戳格式.您将从4(?)列减少到一列.为什么这样好?因为您可以使用PHP date()来格式化满足您的需求! (我相信您需要使用strtotime(),而且注释中还有人具有时区转换功能)

and move to a timestamp format. You'll go from 4(?) columns down to one. Why is this good? Because you can use PHP date() to format the date for you into exactly what you need! (you'll need to use strtotime() I believe and also someone has a timezone conversion function in the comments)

从iCal角度看需要做什么:

Looking at what needs to be done from an iCal perspective:

 echo "DTSTAMP:<year><month><day>T<hour><minutes><seconds>Z\n";  // Time iCal item was made
 echo "DTSTART:<year><month><day>T<hour><minutes><seconds>Z\n";  // Start time
 echo "DTEND:<year><month><day>T<hour><minutes><seconds>Z\n";    // End time


Z代表UTC时间或绝对时间.
您可以在文件中设置时区,然后将转换留给日历程序.
http://tools.ietf.org/html/rfc5545#section-3.2. 19


The Z represents UTC time, or absolute time.
You can set the timezone in the file and leave the conversion to the calendar program.
http://tools.ietf.org/html/rfc5545#section-3.2.19

这篇关于动态创建.ics文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆