【发布时间】:2019-08-26 18:36:36
【问题描述】:
我正在编写如下所示的 php 代码,其中包含我想要更改的 air_date 当从 UI 中选择不同的时区时。
PHP代码:
$cols = array(
'e.description_' . $opp_lang . ' as translation',
's.air_date', // This is the entry point of air_date and its been used everywhere.
'e.program_id',
);
我用于时区的逻辑:
function tz_translations( $lang = 'en' ) {
$tz_translations = [
'en' => [
'PST' => [
'label' => 'PT',
'diff' => 'subtract 3 hours',
],
'EST' => [
'label' => 'ET',
'diff' => 'subtract 0 hours',
],
],
'fr' => [
'HNP' => [
'label' => 'HP',
'diff' => 'subtract 3 hours',
],
'HNE' => [
'label' => 'HE',
'diff' => 'subtract 0 hours',
],
],
];
return $tz_translations[ $lang ];
}
<ul id="js-timezone-picker">
<?php foreach ( $tz_translations as $key => $tz ) :
$tz_param = strtolower( $tz['label'] );
$active = ( $current_tz === $key ) ? 'active' : '';
?>
<li>
<button id="<?php echo esc_attr( 'js-time-' . $tz_param ) ?>"
class="<?php echo sanitize_html_class( $active ) ?>"
data-timezone="<?php echo esc_attr( $tz_param ) ?>"><?php echo esc_html( $tz['label'] ) ?></button>
</li>
<?php endforeach; ?>
</ul>
When PT/ET is selected then it becomes the following on inspect:
<button id="js-time-pt" class="" data-timezone="pt">PT</button>
<button id="js-time-et" class="" data-timezone="et">ET</button>
问题陈述:
我想知道我应该在上面的 php 代码中进行哪些更改,以便当 从 UI/JS 代码中选择不同的时区时,air_date在 php 代码中会根据时区自动更改。
【问题讨论】:
-
你好。 “我应该做出哪些改变”是一个过于宽泛的问题。相反,请尝试将您的问题限制在特定问题上。请阅读帮助中心的How do I ask a good question?。此外,您应该阅读timezone 标签中的其他问题,以及the timezone tag wiki 和PHP's
DateTimedocumentation,其中包括时区。 -
请注意,您需要使用
America/New_York等实际时区标识符,而不是ET。您也不能简单地应用像'subtract 3 hours'这样的差异,因为这不考虑夏令时和其他时区的奇怪情况。 -
@MattJohnson 我试图提供最大的信息。好的,我会尽量减少我的问题
-
你读过Timezone conversion in php吗?很难判断你是否要求其他任何东西。
-
“过滤日期”到底是什么意思?
s.air_date的值是多少?一个约会?采用什么格式 - 是否始终采用这种格式?
标签: javascript php html user-interface timezone