简体   繁体   English

支持AM / PM时间格式以及24小时

[英]support AM/PM time format as well as 24 hour

I've got a regex like so: 我有这样一个正则表达式:

/(\d\d?[\/-]\d\d?[\/-]\d{2,4}) (\d\d:\d\d:\d\d): ([^:]+): (.*)/g

this currently supports a string that looks like this: 16/05/14 09:38:22: Jons Janssen: Yo. 目前,该字符串支持如下所示的字符串: 16/05/14 09:38:22: Jons Janssen: Yo.16/05/14 09:38:22: Jons Janssen: Yo.

I need it to support 16/05/14 11:19:33 pm: Jons Janssen: Yo Bas. 我需要它来支持16/05/14 11:19:33 pm: Jons Janssen: Yo Bas. As well. 也一样

How do I do this? 我该怎么做呢?

Change your regex like so: 像这样更改您的正则表达式:

(\d\d?[\/-]\d\d?[\/-]\d{2,4}) (\d\d:\d\d:\d\d(?: [ap]m)?): ([^:]+): (.*)

(?: [ap]m)? is a non-capturing group that matches either am or pm . 是与ampm匹配的非捕获组。 The ? ? at the end indicates that the whole group is optional. 最后表示整个组是可选的。

Regex demo 正则表达式演示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将格式时间 AM / PM 更改为 24 小时时间轴日 fullcalendar - Change Format Time AM / PM to 24 hour Timeline Day fullcalendar 时间序列流,删除x轴上的am / pm和24小时格式 - time series stream, removing am/pm on x axis and 24 hour format 将时间字符串HH:mm am / pm更改为24小时时间 - change time string of HH:mm am/pm to 24 hour time 如何以12小时AM / PM格式添加24小时选项? - How to add options for 24 hours in 12 hour AM/PM format? 如何将 am/pm 日期转换为 24 小时时间 - How to convert am/pm date to 24 hour time 12 小时 Javascript 时钟显示 24 时间,错误的 AM/PM - 12 hour Javascript Clock Showing 24 time, Wrong AM/PM Javascript:将 24 小时时间字符串转换为带有 AM/PM 且无时区的 12 小时时间 - Javascript: convert 24-hour time-of-day string to 12-hour time with AM/PM and no timezone 使用 Javascript 将 24 小时制转换为 12 小时制 - Converting 24 hour time to 12 hour time w/ AM & PM using Javascript 什么是在javascript中将上午/下午时间转换为24小时时间的简单方法 - What's a simple way to convert between an am/pm time to 24 hour time in javascript 以 12 小时格式(上午 9 点至下午 6 点)而不是 24 小时显示营业时间 - Display business opening hours in 12 hour format (9am - 6pm) instead of 24 hours
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM