Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
 import java.util.Map;

DateFormatConverter that Converts SimpleDataFormat pattern strings into equivalent patterns used in moment.js.
     private static final Map<StringStringTOKEN_MAP = new HashMap<>();
     static {
         // this is actually not correct, but the closest we can get (will work (999-99)/999 * 100 % of the time ;-)
         map("''""'"); // special quoting case of SimpleDateFormat
    public String getMappedToken(String token) {
        return .get(token);
    public boolean hasMappedToken(String token) {
        return .containsKey(token);

SimpleDateFormat uses the single quote ' character to escape character sequences, where as moment.js uses brackets [ ]. This method converts these different escape characters. A special case is '' which is covered by the token conversion (as it shows up as a single ' in a SimpleDateFormat formatted date.

o the index of the quote beginning a quoted block
c the index of the quote closing a quoted block
str the string builder containing the pattern
    protected void convertEscape(int oint cStringBuilder str) {
    protected boolean isConvertingEscapes() {
        return true;
    private static void map(String simpleDateFormatString momentJsFormat) {
New to GrepCode? Check out our FAQ X