![](/img/trans.png)
[英]Convertion of date format using jQuery or javascript(Without using any lib)
[英]javascript time format convertion using regular expression
AM使用正則表達式檢查格式為HH:MM的給定時間
例如。,
var re = /^\s*([01]?\d|2[0-3]):?([0-5]\d)\s*$/;
if ((m = s.match(re))) {
result = (m[1].length == 2 ? "" : "0") + m[1] + ":" + m[2];
}
哪個工作正常。但是我想將給定的數字轉換並顯示為給定的正則表達式格式。任何人都可以幫我找到解決方案。
范例:
如果輸入1,則必須將其轉換為01:00或1.0轉換為01:00
或者除了正則表達式之外還有其他任何轉換方法
例如:
format2 = function(n) { n = parseInt(n, 10); return (n < 10 ? "0" : "") + n }
time = "1"
p = (time + ":0").split(":")
formattedTime = format2(p[0]) + ":" + format2(p[1]);
這會將所有可能的數字輸入轉換為HH:MM格式
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.