Php strtotime() function

I am trying khổng lồ create a select các mục starting from the current date of the user. I want it so that it is phối to lớn midnight in unix timestamp format.

Bạn đang xem: Php strtotime() function

This is all I"m doing:

$today = strtotime("today");echo $today;This is my result:

1333144800which is: Fri, 30 Mar 2012 22:00:00 GMT according to lớn Epoch Converter (incorrect by a couple hours.)



If you want strtotime() to return a timestamp relative lớn UTC (00:00:00 UTC instead of e.g. 00:00:00 UTC+2, if your system is phối khổng lồ a timezone with an offmix of 2 hours against UTC/GMT), you need lớn specify that:

$today = strtotime("today UTC");


GMT (+0) time

eđến $today = strtotime("today GMT");eđến "" . $today = date("d-m-Y H:i:s", $today);We expect that your hệ thống runs at GMT - that is the best (for maneuvering with time displays later). If not, you MUST adjust php.ini mix this "date.timezone = GMT".

When you get that done, you will see 00:00 with my codes.

Then, you must develop function (ie DisplayDate()) in your script khổng lồ display dates of your website correctly if

youre not in GMT areaor/and if you want for your users to see times in their timezone with timezone selection for example.

Xem thêm: Phần Mềm Iqboard, Phần Mềm Iqboard, Bảng Tương Tác Iqboard Rpt 87

DisplayDate() should include tư vấn for daylight changes also (0, or +1 hour / summer & winter time).

edited Mar 31 "12 at 17:49
answered Mar 31 "12 at 17:12

67688 silver badges1919 bronze badges
Add a phản hồi |
strtotime( $time )is designed khổng lồ return a unix timetamp, meaning, it will return the number of seconds since jan 1, 1970.

To get around this, use something like:

$today = date("d/m/Y H:i:s", strtotime("today"));eđến $today;
answered Mar 31 "12 at 16:36

1,59822 gold badges1616 silver badges2626 bronze badges
Add a bình luận |
You might have sầu to lớn specifically phối the time as well as the day:

$today_midnight = strtotime("today UTC 00:00");
answered Mar 31 "12 at 16:47
10.9k88 gold badges4545 silver badges8383 bronze badges
Add a phản hồi |
You should kiểm tra the timezone configuration in your php.ini file. In my case (I live in El Salvador) I had to change it lượt thích this:

date.timezone = America/El_Salvador
answered Mar 31 "12 at 16:36
3,37922 gold badges2424 silver badges3939 bronze badges
Add a bình luận |

Your Answer

Thanks for contributing an answer to Staông chồng Overflow!

Please be sure to lớn answer the question. Provide details and mô tả your research!

But avoid

Asking for help, clarification, or responding khổng lồ other answers.Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.

Xem thêm: Download Game Yi Jian Chinese Fighting Mobile Game Info + Download Link

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Facebook
Sign up using E-Mail and Password

Post as a guest

E-Mail Required, but never shown

Post as a guest

Thư điện tử

Required, but never shown

Post Your Answer Discard

By clicking “Post Your Answer”, you agree khổng lồ our terms of service, privacy policy và cookie policy

Not the answer you're looking for? Browse other questions tagged php unix time strtotime timezone-offmix or ask your own question.

The Overflow Blog
Featured on Meta
strtotime not inserting into lớn database
Calculate relative time in C#
How khổng lồ get the current time in Pydong dỏng
What vị 'real', 'user' and 'sys' mean in the output of time(1)?
Convert a Unix timestamp to lớn time in JavaScript
How do I get time of a Pythuôn program's execution?
PHPhường strtotime() function wrong by 1 hour?
How to get current time và date in Android
PHP. strtotime incorrect conversion
What's the best way khổng lồ convert a date and time inlớn a timestamp using php?
PHPhường strtotime and DST
Hot Network Questions more hot questions

Question feed
Subscribe khổng lồ RSS
Question feed To subscribe khổng lồ this RSS feed, copy và paste this URL into your RSS reader.

Stack Overflow
Stachồng Exchange Network
site design / logo © 2021 Staông chồng Exchange Inc; user contributions licensed under cc by-sa. rev2021.3.18.38837

Chuyên mục: