dtgu21994537 2010-02-13 04:12
浏览 20
已采纳

奇怪的行为计算时区差异

I can't explain this. I have the following:

     $time += $res['timezone']; (The array equates to -5*3600 (EST))
     return gmstrftime('%c',$time);

When I echo $res['timezone'], I get "-5*3600" which is correct. When I put the array value in front of the time variable, I get the incorrect time. If I comment out the array value and replace it with -5*3600, I get the correct result. Why??

  • 写回答

1条回答 默认 最新

  • 普通网友 2010-02-13 04:16
    关注

    because the string "-5*3600" and the expression -5*3600 aren't the same thing. You could try to put eval around the array value, like so:

     $time += eval($res['timezone']); //(The array equates to -5*3600 (EST))
     return gmstrftime('%c',$time);
    

    Note that this is a very bad idea, as it is both slow and insecure. If you want to store -5*3600 in the array, then calculate the value and store the result in the array:

    $res['timezone'] = -5*3600;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么