PHP Date to iCal date format for DTSTART

吃可爱长大的小学妹 提交于 2019-12-04 18:35:57

问题


Is there an easy way to get the correct format for an iCal DTSTART using php date?

I need the format to look like: 20111008T110000 or 20111008 (that one is easy) if I don't have any time.

Does PHP date have a quick way to do this, specifically one that adds the time or removes it when needed?


回答1:


There isn't any native PHP function or date format that I'm aware of, so you'll need to create your own function. Something like this:

function getIcalDate($time, $inclTime = true)
{
    return date('Ymd' . ($inclTime ? '\THis' : ''), $time);
}

As hakre pointed out in a comment, the date formatter can't distinguish between a date with time and a date without time - you'll have to decide the logic behind that.




回答2:


date('Ymd\THis', time())

You can replace time() with your own timestamp.




回答3:


This is might be you are looking for link and this also can help you.

mktime function to make timestamp as you want including time or only date to it.



来源:https://stackoverflow.com/questions/7678830/php-date-to-ical-date-format-for-dtstart

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!