Could you please advice how to remove an hour from unixtime.
I have a unixtime and i need to remove an extra hour before converting to normal time. Could you please advice how to do this?
Also, is Unixtime affected by the GMT time changes?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Unix timestamps are measured in seconds, there are 3600 seconds in an hour (60 minutes, each with 60 seconds = 60*60 = 3600), so just subtract:
You can also use
strtotimeto accomplish the same:Or if
$timestampis simply “now” you can callstrtotimewithout the second parameter:So you seem to be looking for GMT time instead, the trouble is GMT can include Daylight Savings Time (DST), and the “GMT” date functions in PHP actually return UTC time, which has no concept of DST. Luckily you can detect if it’s DST using PHP, and basically adjust appropriately.
Get UTC time using
gmdate:Detect if it’s DST using
I:gmdate('U')will trail GMT time during DST by an hour, thus you need to give it+3600seconds, or 1 hour when it’s DST, so putting this together: