如何将两个unix时间戳一起添加?

Given that I have 2 timestamps:

1332954000   

which is 18:00pm in human readable format. I got this from strtotime("18:00")

and

1330992000 

which is Tues 6 march 2012 in human readable format

How can I add them together such that it will become Tuesday 6 March 2012 18:00pm in Unix timestamp format?

1332954000 doesn't mean 18:00, it means 1332954000 seconds from 1st Jan 1970.

You can't represent 18:00 in seconds from 1st Jan 1970, so your question is meaningless.

You could represent 18:00 as being equal to 18 * 60 * 60 = 64800 seconds, then add that on to your date, which would make sense.

You could concatenate the strings together then use strtotime on that to get what you want alternatively.

Solution 1

$Var1 = '18:00'; // Not 18:00pm please....
$Var2 = 'Tues 6 march 2012';
$NewTimeStamp = date('U', strtotime($Var1.' '.$Var2));

Solution 2 - Not sure

$Var1 = strtotime('18:00pm') - time();
$Var2 = strtotime('Tues 6 march 2012');
$NewTimeStamp = date('U', $Var1 + $Var2);

Be sure to go read about function.date to know how to format the time but U will give you timestamp.

Also, 18:00pm ain't really a time ... 6:00PM is or 18:00 without PM

The timestamp is just the number of seconds from the 1st of January, 1970. Assuming:

1330992000

Is the correct timestamp for Tues 6 march 2012 at 12:00 AM, then all you need to do is add 18 hours, in seconds to the timestamp.

$timestamp + 64800 = $final_timestamp