Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Current events
Recent changes
Random page
Help
Categories
LemonWiki共筆
Search
Search
Appearance
Log in
Personal tools
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
PHP and MySQL syntax
(section)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Special pages
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==== Convert the datetime to ISO foamt time format ==== Using the [https://www.php.net/manual/en/datetime.createfromformat.php DateTime::createFromFormat]<ref>[https://stackoverflow.com/questions/10306999/php-convert-date-format-dd-mm-yyyy-yyyy-mm-dd PHP convert date format dd/mm/yyyy => yyyy-mm-dd - Stack Overflow]</ref> <pre> $date = DateTime::createFromFormat('d/m/Y', "29/03/2021"); echo $date->format('Y-m-d'); // output: 2021-03-29 $date = DateTime::createFromFormat('M d D Y H:i', "Jun 04 Sun 2023 08:25"); echo $date->format('Y-m-d H:i:s'); // output: 2023-06-04 08:25:00 </pre> The following instruction written by ChatGPT <pre> // The input datetime string $input = "Jun 04 Sun 2023 08:25"; // Specify the input format $inputFormat = "M d D Y H:i"; // Create a DateTime object from the input string $dateTime = DateTime::createFromFormat($inputFormat, $input); // Check if the DateTime object was created successfully if ($dateTime === false) { echo "Failed to parse the input datetime string."; } else { // Format the DateTime object into the desired ISO format $isoFormat = "Y-m-d H:i:s"; $output = $dateTime->format($isoFormat); // Print the output echo $output; // "2023-06-04 08:25:00" } </pre>
Summary:
Please note that all contributions to LemonWiki共筆 are considered to be released under the Creative Commons Attribution-NonCommercial-ShareAlike (see
LemonWiki共筆:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)