从格式01/02/2010开始,jquery修剪前导零
问题描述:
如何将2012年1月26日返回的javascript日期对象修剪为1/26/2012?
它适用于月份或日期。
所以01/01/2012应该被修剪为1/1/2012。
正则表达式? jquery修剪功能?我不知道该怎么做?
How do I trim javascript date object returned as 01/26/2012 into 1/26/2012? it could be applicable for both month or days. So 01/01/2012 should be trimmed as 1/1/2012. Regular expression? jquery trim function? I am not sure how to go on this?
var date=date.replace(/^0+/, '');
或
var trimmed = s.replace(/\b(0(?!\b))+/g, "")
答
对于简单的字符串操作,可以使用RegEx:
For a simple string operation, a RegEx can be used:
date = date.replace(/\b0(?=\d)/g, '')