0

I need a generic function that takes a unix-timestamp representation of a date-time and returns a representation for, say, midnight on the first of the month.

i.e. I pass 1352376093 which represents now (Thu, 08 Nov 2012 12:01:33 GMT) and 1351728000 is returned which represents (Thu, 01 Nov 2012 00:00:00 GMT)

4

2 回答 2

2

此代码段应该可以帮助您解决问题。只需从现有日期中取出月份和年份并将其转换回时间戳即可。

<?php
     $time = 1352376093;
     $date = date('Y-m-01 00:00:00', $time);
     $result = strtotime($date);
于 2012-11-08T12:13:48.347 回答
0

所以最终得到了这个功能:

$earliest_issue = db_result( $result, 0 );
$day_of_month_of_earliest_issue = date("d", $earliest_issue);
$hour_of_month_of_earliest_issue = date("h", $earliest_issue);
$minute_of_month_of_earliest_issue = date("i", $earliest_issue);
$seconds_in_month = date("s", $earliest_issue);
$seconds_in_day_of_month = (($day_of_month_of_earliest_issue*24*60*60)-86400);
$seconds_in_hour_of_month = (($hour_of_month_of_earliest_issue*60*60)-3600);
$seconds_in_minute_of_month = (($minute_of_month_of_earliest_issue*60));
$start_time_of_query = ($earliest_issue - $seconds_in_day_of_month - $seconds_in_hour_of_month - $seconds_in_minute_of_month - $seconds_in_month);

return $start_time_of_query;

$earliest_issue开始日期在哪里...

如果有人阅读本文具有我希望的更优雅的功能,请贡献,谢谢!

于 2012-11-08T12:54:30.807 回答