Converts the date format pattern used by Weka to the date format pattern used by Python's datetime.strftime().
770522
def convert_weka_to_py_date_pattern(p):
    
    # https://docs.python.org/2/library/datetime.html#strftime-strptime-behavior
    # https://www.cs.waikato.ac.nz/ml/weka/arff.html
    p = p.replace('yyyy', r'%Y')
    p = p.replace('MM', r'%m')
    p = p.replace('dd', r'%d')
    p = p.replace('HH', r'%H')
    p = p.replace('mm', r'%M')
    p = p.replace('ss', r'%S')
    return p
1322680
public String toTimeStr() {
		if (null != this.timeZone) {
			final SimpleDateFormat simpleDateFormat = new SimpleDateFormat(DatePattern.NORM_TIME_PATTERN);
			simpleDateFormat.setTimeZone(this.timeZone);
			return toString(simpleDateFormat);
		}
		return toString(DatePattern.NORM_TIME_FORMAT);
	}
545824
public static Format getDateFormatter(final String pattern) {
		Format format = JKFormatUtil.formatMap.get(pattern);
		if (format == null) {
			format = new SimpleDateFormat(pattern);
			JKFormatUtil.formatMap.put(pattern, format);
		}
		return format;
	}
476731
public static Date parseDate(final String date, final List<String> patterns)
	{
		for (final String pattern : patterns)
		{
			final SimpleDateFormat formatter = new SimpleDateFormat(pattern);
			try
			{
				return formatter.parse(date);
			}
			catch (final ParseException e)
			{
				// Do nothing...
			}
		}
		return null;
	}
841375
public static Date formatDate(Date orig, String... patterns) {
        String pattern = TIMESTAMP_PATTERN;
        if (patterns != null && patterns.length > 0
                && StringUtils.isNotBlank(patterns[0])) {
            pattern = patterns[0];
        }
        return parseDate(DateFormatUtils.format(orig, pattern));
    }
1039516
public static String format(Date date, String... patterns) {
        if (date == null)
            return "";
        String pattern = TIMESTAMP_PATTERN;
        if (patterns != null && patterns.length > 0
                && StringUtils.isNotBlank(patterns[0])) {
            pattern = patterns[0];
        }
        return DateFormatUtils.format(date, pattern);
    }
810805
def strftimegen(start_dt, end_dt):
    
    if start_dt > end_dt:
        raise ValueError("the start datetime is after the end datetime: (%r,%r)" % (start_dt, end_dt))

    def iterftime(string):
        date_subs = [i for i in DATE_FORMATS if i[1].search(string) is not None]
        if not date_subs:
            yield string
        else:
            dt = start_dt
            date_path = string
            while end_dt >= dt:
                for item in date_subs:
                    date_path = item[1].sub(dt.strftime(item[0]), date_path)
                yield date_path
                dt = dt + datetime.timedelta(days=1)

    return iterftime
1103458
def dt_from_rfc8601(date_str):
    
    # Normalize string and adjust for milliseconds. Note that Python 2.6+ has
    # ".%f" format, but we're going for Python 2.5, so truncate the portion.
    date_str = date_str.rstrip('Z').split('.')[0]

    # Format string. (2010-04-13T14:02:48.000Z)
    fmt = "%Y-%m-%dT%H:%M:%S"
    # Python 2.6+: Could format and handle milliseconds.
    # if date_str.find('.') >= 0:
    #    fmt += ".%f"

    return datetime.strptime(date_str, fmt)
46327
public static String toJavaDateTimeFormat(String strftime) {
    if (!StringUtils.contains(strftime, '%')) {
      return replaceL(strftime);
    }

    StringBuilder result = new StringBuilder();

    for (int i = 0; i < strftime.length(); i++) {
      char c = strftime.charAt(i);
      if (c == '%') {
        c = strftime.charAt(++i);
        boolean stripLeadingZero = false;

        if (c == '-') {
          stripLeadingZero = true;
          c = strftime.charAt(++i);
        }

        if (stripLeadingZero) {
          result.append(CONVERSIONS[c].substring(1));
        } else {
          result.append(CONVERSIONS[c]);
        }
      } else if (Character.isLetter(c)) {
        result.append("'");
        while (Character.isLetter(c)) {
          result.append(c);
          if (++i < strftime.length()) {
            c = strftime.charAt(i);
          } else {
            c = 0;
          }
        }
        result.append("'");
        --i; // re-consume last char
      } else {
        result.append(c);
      }
    }

    return replaceL(result.toString());
  }
371254
def format_datetime(self, value, format_):
        
        date_ = make_datetime(value)
        return dates.format_datetime(date_, format_, locale=self.lang)
1357335
def babel2datetime(pattern):
    """"""
    if not isinstance(pattern, DateTimePattern):
        pattern = parse_pattern(pattern)

    map_fmt = {
        # days
        "d": "%d",
        "dd": "%d",
        "EEE": "%a",
        "EEEE": "%A",
        "EEEEE": "%a",  # narrow name => short name
        # months
        "M": "%m",
        "MM": "%m",
        "MMM": "%b",
        "MMMM": "%B",
        # years
        "y": "%Y",
        "yy": "%Y",
        "yyyy": "%Y",
        # hours
        "h": "%I",
        "hh": "%I",
        "H": "%H",
        "HH": "%H",
        # minutes,
        "m": "%M",
        "mm": "%M",
        # seconds
        "s": "%S",
        "ss": "%S",
        # am/pm
        "a": "%p",
    }

    return pattern.format % map_fmt
1055759
def date(self, pattern='%Y-%m-%d', end_datetime=None):
        
        return self.date_time(end_datetime=end_datetime).strftime(pattern)
939619
public static String format(final LocalDate self, String pattern) {
        return self.format(DateTimeFormatter.ofPattern(pattern));
    }
809003
def _datetime_to_date(arg):
    
    _arg = parse(arg)
    if isinstance(_arg, datetime.datetime):
        _arg = _arg.date()
    return _arg
583818
function convert(dateTime, pattern, options) {
	// If no pattern provided setting default one
	var defaultPattern = pattern || '%hh%:%mm% %DD%/%MM%/%YYYY%';
	
	const filters = [
		{
			pattern: /%hh%/g,
			replacement: (function() {
				if(options && options.shortTime && dateTime.getHours() > 12) {
					return dateTime.getHours() - 12;
				} else {
					return validateForOneDigit(dateTime.getHours());
				}
			})()
		},
		{
			pattern: /%mm%/g,
			replacement: validateForOneDigit(dateTime.getMinutes())
		},
		{
			pattern: /%ss%/g,
			replacement: validateForOneDigit(dateTime.getSeconds())
		},
		{
			pattern: /%DD%/g,
			replacement: validateForOneDigit(dateTime.getDate())
		},
		{
			pattern: /%MM%/g,
			replacement: validateForOneDigit(dateTime.getMonth() + 1)
		},
		{
			pattern: /%YYYY%/g,
			replacement: validateForOneDigit(dateTime.getFullYear())
		},
		{
			pattern: /%YY%/g,	//TODO
			replacement: validateForOneDigit(dateTime.getFullYear().toString().slice(2))
		},
		{
			pattern: /%h%/g,
			replacement: (function() {
				if(options && options.shortTime && dateTime.getHours() > 12) {
					return dateTime.getHours() - 12;
				} else {
					return dateTime.getHours();
				}
			})()
		},
		{
			pattern: /%m%/g,
			replacement: dateTime.getMinutes()
		},
		{
			pattern: /%s%/g,
			replacement: dateTime.getSeconds()
		},
		{
			pattern: /%D%/g,
			replacement: dateTime.getDate()
		},
		{
			pattern: /%M%/g,
			replacement: dateTime.getMonth() + 1
		},
		{
			pattern: /%day%/g,
			replacement: days[dateTime.getDay()]
		},
		{
			pattern: /%month%/g,
			replacement: months[dateTime.getMonth()]
		},
		{
			pattern: /%relative%/g,
			replacement: relative(dateTime)
		},
		{
			pattern: /%12h%/g,
			replacement: (function() {
				if(options && options.shortTime) {
					if(dateTime.getHours() > 11) {
						return 'PM';
					} else {
						return 'AM';
					}
				}
			})()
		}
	];
	
	filters.forEach(function(f) {
		defaultPattern = defaultPattern.replace(f.pattern, f.replacement);
	});
	
	if(options && options.shortTime &&
	  pattern.indexOf('%12h%') === -1) {
		if(dateTime.getHours() > 11) {
			defaultPattern += ' PM';
		} else {
			defaultPattern += ' AM';
		}
	}

	return defaultPattern;
}
889734
@Nonnull
    @SuppressFBWarnings("RV_RETURN_VALUE_IGNORED_BAD_PRACTICE")
    public String format(@Nonnull Date date) {
        SimpleDateFormat dateFormat = dateFormats.poll();
        if (dateFormat == null) {
            dateFormat = new SimpleDateFormat(pattern, locale);
            dateFormat.setTimeZone(timeZone);
        }
        try {
            return dateFormat.format(date);
        } finally {
            dateFormats.offer(dateFormat);
        }
    }
628891
def strftime(date_time=None, time_format=None):
        
        if not date_time:
            datetime_now = datetime.now()
        else:
            datetime_now = date_time
        if not time_format:
            time_format = '%Y/%m/%d %H:%M:%S'
        return datetime.strftime(datetime_now, time_format)