这篇文章主要介绍了php将12小时制转换成24小时制的方法,涉及php时间操作的相关技巧,非常具有实用价值,需要的朋友可以参考下
本文实例讲述了php将12小时制转换成24小时制的方法。分享给大家供大家参考。具体如下:
php将12小时制转换成24小时制,输入格式为:02:30:00 pm 转换成:14:30:00
<?php function to_24_hour($hours,$minutes,$seconds,$meridiem){ $hours = sprintf('%02d',(int) $hours); $minutes = sprintf('%02d',(int) $minutes); $seconds = sprintf('%02d',(int) $seconds); $meridiem = (strtolower($meridiem)=='am') ? 'am' : 'pm'; return date('H:i:s', strtotime("{$hours}:{$minutes}:{$seconds}{$meridiem}")); } echo to_24_hour( 1, 2, 3, 'pm' ); // Returns 13:02:03 echo to_24_hour( '02', '30', '00', 'pm' ); // Returns 14:30:00 ?>

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Notepad++7.3.1
Easy-to-use and free code editor

WebStorm Mac version
Useful JavaScript development tools

Dreamweaver Mac version
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)