❮ PHP Date/Time Reference Show ExampleParse English textual datetimes into Unix timestamps: <?php Try it Yourself » Definition and UsageThe strtotime() function parses an English textual datetime into a Unix timestamp (the number of seconds since January 1 1970 00:00:00 GMT). Note: If the year is specified in a two-digit format, values between 0-69 are mapped to 2000-2069 and values between 70-100 are mapped to 1970-2000. Note: Be aware of dates in the m/d/y or d-m-y formats; if the separator is a slash (/), then the American m/d/y is assumed. If the separator is a dash (-) or a dot (.), then the European d-m-y format is assumed. To avoid potential errors, you should YYYY-MM-DD dates or date_create_from_format() when possible. SyntaxParameter Values
Technical Details
❮ PHP Date/Time Reference Learn PHPPHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages. PHP is a widely-used, free, and efficient alternative to competitors such as Microsoft's ASP. Start learning PHP now » Easy Learning with "PHP Tryit"With our online "PHP Tryit" editor, you can edit the PHP code, and click on a button to view the result. Example<!DOCTYPE html> <?php </body> Try it Yourself » Click on the "Try it Yourself" button to see how it works. PHP ExercisesPHP ExamplesLearn by examples! This tutorial supplements all explanations with clarifying examples. See All PHP Examples PHP Quiz TestLearn by taking a quiz! This quiz will give you a signal of how much you know, or do not know, about PHP. Start PHP Quiz! My LearningTrack your progress with the free "My Learning" program here at W3Schools. Log into your account, and start earning points! This is an optional feature, you can study W3Schools without using My Learning.
PHP ReferencesW3Schools' PHP reference contains different categories of all PHP functions, keywords and constants, along with examples. Kickstart your careerGet certified by completing the course Get certified w3schoolsCERTIFIED.2022Hàm Bài viết này được đăng tại freetuts.net, không được copy dưới mọi hình thức. Cú phápCú pháp: Trong đó:
Kết quả trả vềHàm sẽ trả về một chuỗi thời gian đúng với định dạng Bài viết này được đăng tại [free tuts .net] Ví dụCách sử dụng hàm Code echo date("F j, Y, g:i a")."<br />"; echo date("m.d.y")."<br />"; echo date("j, n, Y")."<br />"; echo date("Ymd")."<br />"; echo date('h-i-s, j-m-y, it is w Day')."<br />"; echo date('\i\t \i\s \t\h\e jS \d\a\y.')."<br />"; echo date("D M j G:i:s T Y")."<br />"; echo date('H:m:s \m \i\s\ \m\o\n\t\h')."<br />"; echo date("H:i:s")."<br />"; echo date("Y-m-d H:i:s")."<br />"; Kết quả May 4, 2017, 2:22 pm 05.04.17 4, 5, 2017 20170504 02-22-35, 4-05-17, 2231 2235 4 Thupm17 it is the 4th day. Thu May 4 14:22:35 ICT 2017 14:05:35 m is month 14:22:35 2017-05-04 14:22:35 Định dạng thời gian tại một thời điểm nào đó. Code $date = mktime(15,50,30,4,30,2017); echo date("F j, Y, H:i a", $date)."<br />"; echo date("Y-m-d H:i:s", $date)."<br />"; Kết quả April 30, 2017, 15:50 pm 2017-04-30 15:50:30 Tham khảo: php.net Một phần kiến thức trong lập trình PHP căn bản đó là xử lý thời gian, ngày, tháng với hàm Date() và Time(). Bài viết sau sẽ hướng dẫn bạn cách sử dụng Date và Time một cách dễ dàng.
Hàm Date() trong PHP và cách sử dụngCú pháp: date( $format, $timestamp); $format: định dạng biến trả vể $timestamp: là số nguyên Unix timestamp. nếu để trống nó sẽ lấy về thời gian hiện tại. Các kiểu Format:
Ví dụ: <?php echo date('H:i:s d-m-Y'); ?> Khi bạn chạy đoạn code trên nó sẽ xuất ra giờ, phút, giây và ngày, tháng, năm. Các kiểu viết giờ, tháng, năm khác: <?php echo date("h:i:s") . "<br>"; echo date("F d, Y h:i:s A") . "<br>"; echo date("h:i a"); ?> Hàm time() PHP sẽ lấy thời gian về thời điểm hiện tại. Nó sẽ trả về số giây tính từ thời điểm 00:00:00 1/1/1970. Cú pháp: time() Ví dụ: <?php // 7 ngày; 24 giờ; 60 phút; 60 giây $nextWeek = time() + (7 * 24 * 60 * 60); echo 'Hôm nay: '. date('Y-m-d') ."<br>"; echo 'Tuần tới: '. date('Y-m-d', $nextWeek) ."<br>"; ?> Kết thúc bài học này bạn đã hiểu 2 hàm date() và time() để lấy lấy ngày giờ hiện tại trong PHP chưa nào? Trong những bài tiếp theo mình sẽ tiếp tục chia sẻ những kiến thức PHP hay nhất mời bạn cùng tiếp tục theo dõi tại Quach Quynh blog nhé! |