dsc862009 2015-03-17 09:04
浏览 71
已采纳

PHP DateTime :: format('U')从现在开始返回时间戳,而不是从指定日期返回?

I have a DateTime object, initialized with a specific date:

$inputString = '06102013';
$myDate = DateTime::createFromFormat('mdY', $inputString);

Now I want to give it out in different Formats, using

$myFormat = 'd.m.Y';
$myDate->format($myFormat);

This works perfectly fine for all formats up until the point where I say:

$myFormat = 'U';

Then $myDate->format('U'); contains just the current timestamp (the actual time when the function is called). But how do I get the timestamp from the original input date, $inputString in my case?

If this is important: I'm using PHP 5.3, but plan on upgrading soon.

Edit: Forgot to mention that

$myDate->getTimestamp();

also returns the time of calling, not the original time that the DateTime object was created with!

  • 写回答

1条回答 默认 最新

  • dsjq62428 2015-03-17 09:19
    关注

    The hours, minutes, seconds part of the timestamp will refer to the current time, yes, because your input timestamp does not contain this information. PHP fills in the blanks from the current time at the point of instantiation. However, the day, month and year part of the timestamp represent your input in any version of PHP I tested (see http://3v4l.org/2Or6T).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码