duanshangying5102 2013-12-15 10:11
浏览 38
已采纳

与本地时间相比更改PHP变量

I Want to change the contect of $time variable. as the local time changes Like If

The localtime is Between 9-10am then $time="10:00 - 10:59"
The localtime is Between 10am-11am then $time="11:00 - 10:59"
The localtime is Between 11am-12pm then $time="12:00 - 12:59"
The localtime is Between 12pm-1pm then $time="13:00 - 13:59"

& Soo On.!!

For this i Can created a Mysql table name as Time & Have added the value. & fetching the value in variable $time.

Now Have 24 Hours Cron Jobs & a 24 PHP script to change the value of That sql. & add the cron of 24 files on different time to change the value. But its Too Big Task.

Any One Knows Any Short & Cute Method to apply the different vales in the variabe Only Using PHP. :) Thankx In advance..

  • 写回答

1条回答 默认 最新

  • 普通网友 2013-12-15 10:23
    关注
    $hour = (1 + date("H")) % 24;
    $two_digits = sprintf("%02d", $hour);
    $time = "{$two_digits}:00 - {$two_digits}:59";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突