我需要计算出两个时区之间的小时差,当前面的时区移动到第二天时,我遇到了一些问题。
例子:
//Let's say it is 11pm 23:00 in LA
$local_tz = new DateTimeZone('America/Los_Angeles');
$local = new DateTime('now', $local_tz);
$local_hour = $local->format('H');
//NY is 3 hours ahead, so it is 2am, 02:00
$user_tz = new DateTimeZone('America/New_York');
$user = new DateTime('now', $user_tz);
$user_hour = $user->format('H');
Run Code Online (Sandbox Code Playgroud)
按照这个问题中的例子(计算不同时区日期之间的小时数)我得到了一个不正确的结果:
$diff = $user_tz->getOffset($local);
error_log('$diff '.gmdate("H:i:s", $diff)); //outputs 20:00:00
Run Code Online (Sandbox Code Playgroud)
如果在洛杉矶是下午 4 点,那么在纽约是下午 7 点,那么很容易:
$time_diff = ($user_h - $local_h); //$time_diff = 3;
Run Code Online (Sandbox Code Playgroud)
但是当纽约移动到第二天时,我再次得到错误的结果:
$time_diff = ($user_h - $local_h); //$time_diff = -21;
Run Code Online (Sandbox Code Playgroud)
那么我该如何解释另一个时区已经移动到新的一天呢?
如何在没有空行的情况下将3x2的网格更改为2x3,其中一行结束而另一行开始?
例如:
<div class="row">
<div class="col-md-4 col-sm-6">
content
</div>
<div class="col-md-4 col-sm-6">
content
</div>
<div class="col-md-4 col-sm-6">
content
</div>
</div>
<div class="row">
<div class="col-md-4 col-sm-6">
content
</div>
<div class="col-md-4 col-sm-6">
content
</div>
<div class="col-md-4 col-sm-6">
content
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
这就是我想要实现的目标:
这个:

对此: 
但相反,我得到了这个:
我正在使用MySQL表,我需要为每行增加一列中的值,其中超过6.5米.
col类型是varchar并且可以包含整数或字符串(即+1).表类型是MyISAM.
我用PHP尝试过这个:
$adjust_by = 1;
foreach ($options as $option) {
$original_turnaround = $option['turnaround'];
$adjusted_turnaround = $option['turnaround'];
if (preg_match('/\+/i', $original_turnaround)) {
$tmp = intval($original_turnaround);
$tmp += $adjust_by;
$adjusted_turnaround = '+'.$tmp;
} else {
$adjusted_turnaround += $adjust_by;
}
if (!array_key_exists($option['optionid'], $adjusted)) {
$adjusted[$option['optionid']] = array();
}
$adjusted[$option['optionid']][] = array(
'original_turn' => $original_turnaround,
'adjusted_turn' => $adjusted_turnaround
);
}//end fe options
//update turnarounds:
if (!empty($adjusted)) {
foreach ($adjusted as $opt_id => $turnarounds) {
foreach ($turnarounds as $turn) …Run Code Online (Sandbox Code Playgroud) 我有一个非常简单的OO类结构,无法理解为什么子类没有继承父类的属性和方法.
这是我设置的基本示例:
//Main class:
class Main{
//construct
public function Main(){
//get data from model
$data = $model->getData();
//Get the view
$view = new View();
//Init view
$view->init( $data );
//Get html
$view->getHTML();
}
}
//Parent View class
class View{
public $data, $img_cache;
public function init( $data ){
$this->data = $data;
$this->img_cache = new ImageCache();
}
public function getHTML(){
//At this point all data is intact (data, img_cache)
$view = new ChildView();
//After getting reference to child class all data is …Run Code Online (Sandbox Code Playgroud)