PHP日期为DTSTART的iCal日期格式 [英] PHP Date to iCal date format for DTSTART

查看:495
本文介绍了PHP日期为DTSTART的iCal日期格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我需要格式如下:20111008T110000或20111008(那个是一个简单的方法来获取iCal DTSTART的正确格式?很简单)如果我没有任何时间。



PHP日期有一个快速的方法来做,特别是添加时间或删除它需要时?

解决方案

我没有任何本机PHP函数或日期格式,因此您需要创建你自己的功能这样的东西:

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

正如hakre在评论中指出的那样,日期格式化程序无法区分一个时间和日期没有时间的日期 - 你必须决定背后的逻辑。


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?

解决方案

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, $incl_time = true)
{
    return $incl_time ? date('Ymd\THis', $time) : date('Ymd', $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.

这篇关于PHP日期为DTSTART的iCal日期格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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