开发者

Handling timezone offset in PHP with UNIX timestamp

开发者 https://www.devze.com 2023-01-28 19:14 出处:网络
I have a table of \'notifications\' which may or may not be sent in any 24 hour period. Each notification has it\'s own timezone offset from GMT, so I h开发者_如何学JAVAave a column for offset which w

I have a table of 'notifications' which may or may not be sent in any 24 hour period. Each notification has it's own timezone offset from GMT, so I h开发者_如何学JAVAave a column for offset which will be +/- in seconds.

I need to create a PHP script which will regularly (via cron) check the database for sent notifications, and then reset them to unsent if their time has passed 00:00 for that day. I'm really struggling with the best way to do this - is there a simple calculation I can make?

I was thinking of something around getting the UNIX time for the server's midnight using mktime() [my server is in GMT], and working it out with the offset in seconds, but every way I think of seems wrong.

Something like:

if(!mktime()-$notifcationTimezone > $serverMidnight){}

I'm not saying this doesn't work, but I don't think it will work when the server elapses into another day. It just confuses me, and I have no faith in it.


Isnt this just a simple comparison with strtotime and you dont even need to add up the offset. You can use the date function to set a specific time you want to pass to the strtotime which you want to use to compaire against.

To give us a better idea show us a real example from you database and what the cron looks like right now.

I'm not totaly sure what you are trying to pull of here but, what you might wanna think about is do you really want to reset anything, is it needed? You could fill in at what date your notification got send. If it does not match the date of today you want to resend it again?

0

精彩评论

暂无评论...
验证码 换一张
取 消