修改用户服务器时间,用户的日期和时间转换为服务器的日期和时间在php

做了一个函数来完成这项工作:

/*

* The function week_times() converts a a time and a set of days into an array of week times. Week times are how many seconds into the week

* the given time is. The $offset arguement is the users offset from GMT time, which will serve as the approximation to their

* offset from UTC time

*/

// If server time is not already set for UTC, uncomment the following line

//date_default_timezone_set('UTC');

function week_times($hours, $minutes, $days, $offset)

{

$timeUTC = time(); // Retrieve server time

$hours += $offset; // Add offset to user time to make it UTC time

if($hours > 24) // Time is more than than 24 hours. Increment all days by 1

{

$dayOffset = 1;

$hours -= 24; // Find out what the equivelant time would be for the next day

}

else if($hours < 0) // Time is less than 0 hours. Decrement all days by 1

{

$dayOffset = -1;

$hours += 24; // Find out what the equivelant time would be for the prior day

}

$return = Array(); // Times to return

foreach($days as $k => $v) // Iterate through each day and find out the week time

{

$days[$k] += $dayOffset;

// Ensure that day has a value from 0 - 6 (0 = Sunday, 1 = Monday, .... 6 = Saturday)

if($days[$k] > 6) { $days[$k] = 0; } else if($days[$k] < 0) { $days[$k] = 6; }

$days[$k] *= 1440; // Find out how many minutes into the week this day is

$days[$k] += ($hours*60) + $minutes; // Find out how many minutes into the day this time is

}

return $days;

}

?>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值