【发布时间】:2012-09-03 16:25:33
【问题描述】:
我在 php 手册“日期”中找到了这个函数。
<?php
// 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;
}
?>
我有一个像$event_time[0] 这样的变量,它拥有像14:00 这样的时间格式,即下午2 点。如何将此时间格式转换为十进制以将其传递给上面的unixToiCal() 函数?
感谢您的回复。
更新:
好吧,看来我完全糊涂了。谢谢你们清理事情。并没有真正了解该函数的第二个参数的用途。我来自奥地利,所以 UTC 偏移量应该是 +2 小时,对。
我还有一个关于strtotime() 方法的问题。
我有两个变量……$time 和 $date……我遇到的问题是 $date 已经是像 1347667200 这样的时间戳,$time 是一个“字符串”(我猜)@987654332 @ 或14:00。
如何将这两个值与表示确切日期和时间的时间戳结合起来?
【问题讨论】:
-
你到底想做什么?在该示例中,1.75 表示时区偏移量,而不是小时数。对我来说,该示例似乎完全忽略了适当的夏令时。
-
时间戳保存自
epoch(1970 年 1 月 1 日)以来的毫秒数,所以如果你只有几个小时,除非你对 1970 年 1 月 1 日的 iCal 条目没问题,否则它是不够的。跨度> -
@WebnetMobile.com - 秒,而不是毫秒。这不是 Javascript。请注意,数学假设每小时 3600 次。
-
在上述代码的情况下是正确的,但我提到了 unix 时间戳的常见含义,它自纪元以来一直保持毫秒。看来我不够精确:)
标签: php date time timestamp icalendar