1

うるう年を考慮して、月と年だけを指定して、任意の月の合計時間を抽出する必要があります。

これまでの私のコードは次のとおりです...

$MonthName = "January";
$Year = "2013";

$TimestampofMonth = strtotime("$MonthName  $Year");
$TotalMinutesinMonth = $TimestampofMonth / 60     // to convert to minutes
$TotalHoursinMonth = $TotalMinutesinMonth / 60    // to convert to hours
4

4 に答える 4

1

あなたはこれを行うことができます:

<?php
$MonthName = "January";
$Year = "2013";
$days = date("t", strtotime("$MonthName 1st, $Year"));
echo $days * 24;
于 2013-04-28T16:57:09.990 に答える
1

その月の日数を計算し、次のように 24 を掛けるだけです。

// Set the date in any format
$date = '01/01/2013';
// another possible format etc...
$date = 'January 1st, 2013';

// Get the number of days in the month
$days = date('t', strtotime($date));

// Write out the days
echo $days;
于 2013-04-28T17:02:33.323 に答える
0

DateTime::createFromFormat日がないから使える

$date = DateTime::createFromFormat("F Y", "January 2013");
printf("%s hr(s)",$date->format("t") * 24);

あなたが営業日を見ているなら、それは別のアプローチです

$date = "January 2013"; // You only know Month and year
$workHours = 10; // 10hurs a day

$start = DateTime::createFromFormat("F Y d", "$date 1"); // added first
printf("%s hr(s)", $start->format("t") * 24);

// if you are only looking at working days

$end = clone $start;
$end->modify(sprintf("+%d day", $start->format("t") - 1));

$interval = new DateInterval("P1D"); // Interval
var_dump($start, $end);

$hr = 0;
foreach(new DatePeriod($start, $interval, $end) as $day) {  
    // Exclude sarturday & Sunday
    if ($day->format('N') < 6) {
        $hr += $workHours; // add working hours
    }
}
printf("%s hr(s)", $hr);
于 2013-04-28T17:03:36.657 に答える