Javascript examples for Date Operation:Time Format
Change GMT time format to 24 hours with regex
<html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <script type="text/javascript"> window.onload=function(){/* ww w. j a v a 2s. c o m*/ //12-hour to 24-hour console.log((new Date()).toLocaleString().replace(/(.+ )(\d+)(:.+)(\wM)/g, function replacer(match, p1, p2, p3, p4) { return p1 + (p4 === "PM" ? (12 + Number(p2)) : p2) + p3; })); } </script> </head> <body> </body> </html>