tailieunhanh - Giải pháp thiết kế web động với PHP - p 43

FORMATTING TEXT AND DATES The DateTime() constructor also takes two optional arguments: a string containing a date and/or time, and a DateTimeZone object. The date/time string for the first argument can be in any of the formats listed at . Unlike MySQL, which accepts only one format, PHP goes to the opposite extreme. The range of valid formats is overwhelming and potentially confusing. For example, to create a DateTime object for Christmas Day 2010, all the following formats are valid: '12/25/2010' '25-12-2010' '25 Dec 2010' 'Dec 25 2010' '25-XII-2010' '' '2010/12/25' '2010-12-25' 'December 25th, 2010' This is not an exhaustive list | FORMATTING TEXT AND DATES The DateTime constructor also takes two optional arguments a string containing a date and or time and a DateTimeZone object. The date time string for the first argument can be in any of the formats listed at http manual en . Unlike MySQL which accepts only one format PHP goes to the opposite extreme. The range of valid formats is overwhelming and potentially confusing. For example to create a DateTime object for Christmas Day 2010 all the following formats are valid 12 25 2010 25-12-2010 25 Dec 2010 Dec 25 2010 25-XII-2010 2010 12 25 2010-12-25 December 25th 2010 This is not an exhaustive list. It s just a selection of valid formats. Where the potential confusion arises is in the use of separators. For example the forward slash is permitted in American-style 12 25 2010 and ISO 2010 12 25 dates but not when the date is presented in European order or when the month is represented by Roman numerals. To present the date in European order the separator must be a dot tab or dash. Dates can also be specified using relative expressions such as next Wednesday tomorrow or last Monday. However there s potential for confusion here too. Some people use next Wednesday to mean Wednesday next week. PHP interprets the expression literally. If today is Tuesday next Wednesday means the following day. This situation offers great flexibility as long as you know where your date and time information is coming from and it conforms to one of the many valid formats. PHP expanded this flexibility even further by introducing a method that allows you to specify a custom format for creating a DateTime object. It s described after the next section because the same technique is used for specifying both output and input formats. You can t use echo on its own to display the value stored in a DateTime object. In addition to echo you need to tell PHP how to format the output using the format method. Formatting dates in PHP The

TỪ KHÓA LIÊN QUAN
crossorigin="anonymous">
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.