0

以下は、私が取り組んでいるテキストで、ユーザーのローカル タイム ゾーンに応じて、オンライン セールの開始時刻を示しています。オンライン セールは常に太平洋時間午前 9 時に開始されますが、毎日ではありません

オンライン販売は午前 9 時 (太平洋夏時間)に始まります。タイム ゾーンの設定に基づく現地時間は、2012 年 9 月 11 日 - 午前 12 時 02 分(HST)で、UTC -10またはPDTから3時間遅れています。販売は 現地時間の午前 XX 時に開始されます。

上記の例では、ユーザーのタイム ゾーンは Pacific/Honolulu であり、データベースに保存され、サインイン時に user_tz というセッションにも設定されます。

ほとんどの変数を計算しました。私はこの部分で立ち往生しています (販売は現地時間のXXamに開始されます。) ...これは、太平洋時間の午前 9 時に相当する現地時間を決定する方法であり、現地時間に相当するものが同じ日翌日かを決定する方法です。太平洋時間よりどれだけ進んでいるかによって異なります。たとえば、オーストラリアのメルボルンでは、メルボルンは太平洋時間より 17 時間進んでいるため、販売は翌日の 9 月 12 日の午前 2 時に開始されます。

上記の例では、「XX」は午前 6:00 である必要があります。

PHP バージョン 5.3.14

<?php
// gets the users time zone offset in seconds from UTC
// shown above as -10
$user_tz_offset = getTimeZoneOffset($_SESSION['user_tz']);

// gets the dst code of the timezone ...example: pdt or pst
// shown above as HST
$dateTime = new DateTime(); 
$dateTime->setTimeZone(new DateTimeZone($_SESSION['user_tz'])); 
$user_tz_dst = $dateTime->format('T'); 

// gets the difference in hours from Pacific time to the users time zone
// shown above as 3
$hours_diff = abs(($user_tz_offset - TZ_OFFSET)/3600);

// gets the users local time
// shown above as September 11, 2012 - 12:02 am HST
$user_time_now = date("F j, Y \- g:i a", (time()+$user_tz_offset));

// add a plus sign to time zones that are not negative
if( !strstr( $user_tz_offset, "-" ))
{
    $add_plus_sign = '+';
}

// determine whether we should say "ahead of" or "behind" respective to Pacific time
// TZ_OFFSET is a constant defined in config
if( $user_tz_offset < TZ_OFFSET)
{
    $behind_or_ahead = 'behind';
}
else
{
    $behind_or_ahead = 'ahead of';

}
?>
4

0 に答える 0