Live Connect を使用してカレンダー イベントを作成しています。彼らのドキュメントによると、イベントに指定された start_time は、UTC から何時間ずれているかを示す必要があります (つまり、+0700 または -0300)。最初の刺し傷として、動作するコードを php マニュアルからつなぎ合わせました。ただし、かなり冗長に「感じます」。それで、文体の観点から、私が得たものをより簡潔なものに整理する方法があるでしょうか? $time_zone は、特定のユーザーに基づいて私が知っているものであることに注意してください。
$dateTimeZone = new DateTimeZone($time_zone);
$dateTime= new DateTime("now", $dateTimeZone);
$gmt_offset = ($dateTime->getOffset())/3600;
$negative = ($gmt_offset<0);
$gmt_offset = abs($gmt_offset);
if ($gmt_offset < 10) {
$gmt_offset = '0'.$gmt_offset.'00';
} else {
$gmt_offset = $gmt_offset.'00';
}
if ($negative) {
$gmt_offset = '-'.$gmt_offset;
} else {
$gmt_offset = '+'.$gmt_offset;
}
ご意見ありがとうございます。
-エリック