PHP Date to iCal date format for DTSTART

后端 未结 3 1321
北恋
北恋 2021-02-13 22:10

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 do

3条回答
  •  深忆病人
    2021-02-13 23:02

    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.

提交回复
热议问题