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).


Share
Follow
edited Mar 31 "12 at 17:49
answered Mar 31 "12 at 17:12
*

XfileXfile
67688 silver badges1919 bronze badges
Add a phản hồi |
3
strtotime( $time )is designed khổng lồ return a unix timetamp, meaning, it will return the number of seconds since jan 1, 1970. http://www.php.net/manual/en/function.strtotime.php

To get around this, use something like:

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

Goldentoa11Goldentoa11
1,59822 gold badges1616 silver badges2626 bronze badges
Add a bình luận |
1
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");
Share
Follow
answered Mar 31 "12 at 16:47
hohnerhohner
10.9k88 gold badges4545 silver badges8383 bronze badges
Add a phản hồi |
0
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
Share
Follow
answered Mar 31 "12 at 16:36
PachinSVPachinSV
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
Submit

Post as a guest


Name
E-Mail Required, but never shown


Post as a guest


Name
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
Linked
1
strtotime not inserting into lớn database
Related
1570
Calculate relative time in C#
3186
How khổng lồ get the current time in Pydong dỏng
1886
What vị 'real', 'user' and 'sys' mean in the output of time(1)?
1289
Convert a Unix timestamp to lớn time in JavaScript
1212
How do I get time of a Pythuôn program's execution?
14
PHPhường strtotime() function wrong by 1 hour?
1158
How to get current time và date in Android
2
PHP. strtotime incorrect conversion
0
What's the best way khổng lồ convert a date and time inlớn a timestamp using php?
0
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.


lang-php
Stack Overflow
Products
Company
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: