Wednesday, 15 August 2012

angularjs - How to trim 0 in day but not in month with format(yyyy-dd-mm) in angular/javascript? -


How can I trim the javascript date object? I have a date format that is (yyyy-dm) date value 2015-03-03 and I want to trim in the first days, but not in months.

Example: When I input: 2015-03-03 return it to 2015-03-03

I try 0 has been trimed in the following codes on the following codes:

  $ scope.date = {"start": "2015-01-26", " End ":" 2015-04-03 "}; From `Var = $ scope.date.from.replace (/ \ b0 (? = \ D) / g, ''); Var to = $ scope.date.to.replace (/ \ b0 (? = \ D) / g, ''); (To) console.log; // Output 2015-1-26 and 2015-4-3 ` 

What should I do?

If you want to remove leading zeros from day:

 < Code> $ scope.date.from.replace (/ - 0 (\ d) $ /, '- $ 1')  

does

Edit

Sorry, I should explain how regular expressions and replacements work.

In a regular expression, -0 (\ d) $ matches a dash, followed by zero after, after a digit, then the end of the string is < Code> () capture the matched digit at a grip position, which is displayed in the replacement string by $ 1 .

The entire match is changed then the replacement string '- $ 1' is a dash, after the matched digit: $ 1 .


No comments:

Post a Comment