PHP 24-hour format date converted to 12-hour date

Source: Internet
Author: User

This afternoon to do a mall station, the use of time-limited seconds to kill the function. Need a JS Select time Plug-in, from the online down a, plug-in is selected to the second, 24-hour system. Need to put

Converted to a 12-hour system. Originally used is the Strtotime function, but found that the 24-hour string in the use of this function converted to a timestamp will be cast to the 12-hour format of the morning, so long as the plug-in to select more than 12 points of time, there will be an error. So, what to do is to convert the 24-hour time into a 12-hour system.

After testing, to the time format, you need to create a DateTime object first. Method is

Then, using

Convert the Date object to the format you want, OK. It is not possible for this function to convert strings directly. That's why I just started to fail.

The specific process is:

Where the start_time parameter of the data array is the string passed over the time format.

Tips: When solving the timestamp problem, the original conversion, also encountered a problem, is to mistakenly set the date parameter to y-m-d h:m:s

Results after uploading, the discovery time has been error. It was later discovered that the minutes were mistakenly set to M, whereas m in date represents the month.

However, when consulting colleagues, colleagues said that the M-parameter in this case

That is, do not show the month, only show when the seconds and minutes with M can be representative of the minute. But after testing, this is not the case. In this case, the conversion of the timestamp will still cause the original error.

So I conclude that M can only be used as a parameter of the month in this function.

The Tips:strtotime function converts time in string format to a timestamp. If you pass in the afternoon, you need to put the morning's information at the end of the day.

Can.

Is there a way to convert a DateTime object to a timestamp? There, I feel that the function format is a bit cumbersome, not try to use.

PHP 24-hour format date converted to 12-hour date

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.