Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
690 views
in Technique[技术] by (71.8m points)

php - One Hour Earlier Than Given Datetime

I'm having a problem here..

Supposed I have this kind of datetime.


$date = strtotime($date);

I need this to be converted into the Unix-timestamp format but one hour earlier..I tried


$date = strtotime($date-86400)

, but seemed to me it is wrong. It returned 0 when I sneaked into the table.

What is the appropriate way to achieve this?

Thanks.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

strtotime will give you the unix timestamp of your date. From this timestamp, you then subtract your hour:

$date = strtotime($date) - 3600; // 3600 = 60 * 60

If you call strtotime($date - 3600), it's like obtaining the time for -3600 (e.g. strtotime(-3600)) which makes no sense because strtotime expects a string as first argument.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...